Advertisement
go6odn28

calculator_exampe

Mar 10th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.52 KB | None | 0 0
  1. import sys
  2. import time
  3.  
  4.  
  5. def jonglior(a, b):
  6.     empty_result_list = []
  7.     while True:
  8.         user_command2 = input('Please Enter your calculation action: multiply(m) | divide(d) | add(a) | subtract(s): ')
  9.         if user_command2 == 'a' or user_command2 == 'm' or user_command2 == 'd' or user_command2 == 's':
  10.             while True:
  11.                 try:
  12.                     a = int(input('Please put your first digit: '))
  13.                     break
  14.                 except ValueError:
  15.                     print("Please enter a number")
  16.  
  17.             while True:
  18.                 try:
  19.                     b = int(input('Could you please put your second digit: '))
  20.                     break
  21.                 except ValueError:
  22.                     print("Please enter a number")
  23.  
  24.         else:
  25.             print('You should use options already mentioned: multiply | divide | add | subtract!: ')
  26.             continue
  27.             # user_command2 = input('Please Enter your calculation action: multiply | divide | add | subtract: ')
  28.         result = 0
  29.  
  30.         if user_command2 == 'm' or user_command2 == 'multiply':
  31.             result = multiply(a, b)
  32.             empty_result_list.append(result)
  33.         elif user_command2 == 'd' or user_command2 == 'divide':
  34.             result = divide(a, b)
  35.             empty_result_list.append(result)
  36.         elif user_command2 == 'a' or user_command2 == 'add':
  37.             result = addition(a, b)
  38.             empty_result_list.append(result)
  39.         elif user_command2 == 's' or user_command2 == 'subtract':
  40.             result = subtraction(a, b)
  41.             empty_result_list.append(result)
  42.  
  43.         print(f'Result is : {result}!')
  44.         n = 2
  45.         while n > 0:
  46.             time.sleep(1)
  47.             n -= 2
  48.         print('Thank you for your input!\n'
  49.               '')
  50.         n = 2
  51.         while n > 0:
  52.             time.sleep(2)
  53.             n -= 2
  54.  
  55.         user_command6 = input('Would you like to continue: Yes | No ?')
  56.         n = 1
  57.         while n > 0:
  58.             time.sleep(1)
  59.             n -= 1
  60.         if user_command6 == 'yes' or user_command6 == 'Yes' or user_command6 == 'y':
  61.             a = int
  62.             b = int
  63.             continue
  64.  
  65.         elif user_command6 == 'no' or user_command6 == 'No' or user_command6 == 'n':
  66.  
  67.             n = 1
  68.             while n > 0:
  69.                 time.sleep(1)
  70.                 n -= 1
  71.  
  72.             print('Calculator is entering sleeping mode after 5 seconds...')
  73.             for i in range(5, 0, -1):
  74.                 time.sleep(1)
  75.                 print(i)
  76.             zx = 1
  77.             while zx > 0:
  78.                 time.sleep(1)
  79.                 zx -= 1
  80.             print('End!')
  81.             zxn = 2
  82.             while zxn > 0:
  83.                 time.sleep(1)
  84.                 zxn -= 1
  85.  
  86.             print(f'The results as numbers are as follows: {empty_result_list}')
  87.             sys.exit(1)
  88.  
  89.  
  90. def multiply(a, b):
  91.     return a * b
  92.  
  93.  
  94. def divide(a, b):
  95.     if b > 0:
  96.         return a / b
  97.     if b <= 0:
  98.         print('Error: Division by Zero or negative number, Please redo operation!')
  99.         nl = 1
  100.         while nl > 0:
  101.             time.sleep(1)
  102.             nl -= 1
  103.         return jonglior(a, b)
  104.  
  105.  
  106. def addition(a, b):
  107.     return a + b
  108.  
  109.  
  110. def subtraction(a, b):
  111.     return a - b
  112.  
  113.  
  114. def main():
  115.     print('Hello, This is simple calculator!')
  116.     n = 1
  117.     while n > 0:
  118.         time.sleep(1)
  119.         n -= 1
  120.     a = int
  121.     b = int
  122.     return jonglior(a, b)
  123.  
  124.  
  125. if __name__ == '__main__':
  126.     main()
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement