MazeDomains

Untitled

Feb 21st, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.97 KB | None | 0 0
  1. #FUNCTION: Simple Maths Operators
  2. def simple_maths():
  3.     #Loop to select a valid operator
  4.    
  5.     valid_operator = False    
  6.  
  7.     while valid_operator == False:
  8.         N1 = int(input('What is the first number? '))
  9.         N2 = int(input('What is the second number '))
  10.        
  11.         operator = str(input('What operation do you want to use - (A)dd / (S)ubtract / (D)ivide / (M)ultiply? '))
  12.        
  13.         if operator == 'A' or operator == 'a':
  14.             #MO = Maths Operator
  15.             MO = '+'
  16.             total = N1 + N2
  17.             valid_operator = True    
  18.         elif operator == 'S'or operator == 's':
  19.             MO = '-'
  20.             total = N1 - N2
  21.             valid_operator = True    
  22.         elif operator == 'D'or operator == 'd':
  23.             MO = '/'
  24.             total = (N1 // N2)
  25.             valid_operator = True    
  26.         elif operator == 'M'or operator == 'm':
  27.             MO = '*'
  28.             total = N1 * N2
  29.             valid_operator = True    
  30.         else:
  31.             print('Please enter A, S, D or M!!!')
  32.             valid_operator = False  
  33.    
  34.     print()
  35.     print('Here is your answer:')
  36.     print (N1 ,MO ,N2 ,'=' ,total)
  37.  
  38. #FUNCTION: Number Averager
  39. def averages():
  40.     a = 0
  41.     n = 0
  42.  
  43.     a = float(input('What is your first number?'))
  44.     n = n+1
  45.     average = a/n
  46.     #print ('The average is', average)
  47.  
  48.     end_loop = False
  49.     while end_loop == False:
  50.    
  51.         another = str(input('Enter another number (y/n)?'))
  52.         if another == 'y':
  53.                 b = float(input('What is your next number?'))
  54.                 a = a + b
  55.                 n = n+1
  56.                 average = a/n
  57.                 print ('You entered ' ,n , 'numbers and the average is', average)
  58.                 end_loop = False
  59.         else:
  60.                 print ('You entered ' ,n , 'numbers and the average is', average)
  61.                 end_loop = True
  62.  
  63. #FUNCTION: Select Maths Operation
  64. def Maths():
  65.     print('This code performs simple maths operations on two numbers')
  66.     option = str(input('Enter (1) for simple maths operation (+-/*); (2) to square a number; (3) to find a square root; or (4) to find an average: '))
  67.  
  68.     if option == '1':
  69.         simple_maths()
  70.  
  71.     elif option == '2':
  72.         SQ = int(input('Enter the number to square: '))
  73.         A = SQ * SQ
  74.         print(SQ, 'squared is: ', A)
  75.        
  76.     elif option == '3':
  77.         SR = int(input('Enter the number to find the square root of: '))
  78.         import math
  79.         SRA = math.sqrt(SR)
  80.         print('The square root of', SR, 'is', SRA)  
  81.  
  82.     elif option == '4':
  83.         averages()
  84.        
  85.     else:
  86.         print ('OK then - Bye!!!!!')
  87.  
  88. #Loop to perform multiple maths operations
  89.  
  90. no_continue = False
  91.  
  92. while no_continue == False:
  93.     hello=input('Do you want to do some maths (Y / N)?')
  94.     if hello == 'Y' or hello =='y':
  95.             Maths()
  96.             no_continue = False
  97.     else:
  98.         print ('Bye!!!')
  99.         no_continue = True
Add Comment
Please, Sign In to add comment