Advertisement
automate_cloud_21

Create my first program in python

Nov 17th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.17 KB | None | 0 0
  1. #program apa yg mau dibuat harus ada if dan loop:
  2. #1. membuat login
  3. #2. membuat existing account
  4. #3. terddapat dua menu login dgn existing account dan create new account
  5. #4. setelah login pilih menu ada tiga pilihan penjumlahan, pengurangan dan perkalian selain itu langsung exit
  6.  
  7. # perlu beberapa perbaikan terutama di mekanisme jika pass dan username salah berkali kali (done dengan cara balik k menu utama)
  8. print("welcome to my first program")
  9. print('============================')
  10. def main_menu():
  11.     print('choose menu: ')
  12.     print('1. Create new account')
  13.     print('2. login with existing account')
  14.     print('choose 1 or 2 to input your choice: ')
  15.     global menu
  16.     menu = input()
  17.     if menu == '1':
  18.         make_account()
  19.     else:
  20.         login()
  21. def make_account():
  22.     #create global variable
  23.     global password
  24.     global username
  25.     print('input your username: ')
  26.     username = input()
  27.     print('input your password: ')
  28.     password = input()
  29.     if len(password) < 4:
  30.         print('password must be at least 4 words please try again: ')
  31.         password = input()
  32.         print('account succesfully created')
  33.         main_menu()
  34.     else:
  35.         main_menu()
  36. def login():
  37.     print(username)
  38.     print(password)
  39.     print('what is your username: ')
  40.     username_existing = input()
  41.     print('what is your password: ')
  42.     password_existing = input()
  43.     if (password_existing != password):
  44.         print('try again back to main menu')
  45.         main_menu()
  46.     else:
  47.         print('sucess')
  48.         main_program()
  49.  
  50. def main_program():
  51.     print('==============================')
  52.     print('1. sum')
  53.     print('2. multipication')
  54.     print('3. sum more than 2 numbers')
  55.     print('4. exit')
  56.     print('choose menu: ')
  57.     choice = input()
  58.     if choice == '1':
  59.         #calling sum menu
  60.         sum()
  61.     elif choice == '2':
  62.         #calling multipication menu
  63.         multipication()
  64.     elif choice == '3':
  65.         #calling sum_numbers function
  66.         sum_number()
  67.     else:
  68.         #exit program
  69.         print('thank you for trying my program !!!')
  70.  
  71. def sum():
  72.     print('input first number: ')
  73.     first_number = int(input())
  74.     print('input second number: ')
  75.     second_number = int(input())
  76.     result = first_number + second_number
  77.     print('here is your result' +' '+ str(result))
  78.  
  79. def multipication():
  80.     print('input first number: ')
  81.     first_number = int(input())
  82.     print('input second number: ')
  83.     second_number = int(input())
  84.     result = first_number * second_number
  85.     print('here is your multipication result' +' '+ str(result))
  86.  
  87. def sum_number():  
  88. # define list variable
  89.     print('input your number and if u want to finish add 0')
  90.     numbers = []
  91.     while True:
  92.         print('input ur numbers' + ' ' + str(len(numbers) + 1)+ ':')
  93.         input_numbers = int(input())
  94.         if input_numbers == 0:
  95.             break
  96.         numbers =numbers + [input_numbers]
  97.     print('here is your numbers:')
  98.     print(numbers)
  99.     result = 0
  100.     for input_numbers in numbers:
  101.         result += input_numbers
  102.     print(result)
  103.     main_program()
  104.  
  105. #calling first function to run main menu
  106. main_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement