Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #FUNCTION: Simple Maths Operators
- def simple_maths():
- #Loop to select a valid operator
- valid_operator = False
- while valid_operator == False:
- N1 = int(input('What is the first number? '))
- N2 = int(input('What is the second number '))
- operator = str(input('What operation do you want to use - (A)dd / (S)ubtract / (D)ivide / (M)ultiply? '))
- if operator == 'A' or operator == 'a':
- #MO = Maths Operator
- MO = '+'
- total = N1 + N2
- valid_operator = True
- elif operator == 'S'or operator == 's':
- MO = '-'
- total = N1 - N2
- valid_operator = True
- elif operator == 'D'or operator == 'd':
- MO = '/'
- total = (N1 // N2)
- valid_operator = True
- elif operator == 'M'or operator == 'm':
- MO = '*'
- total = N1 * N2
- valid_operator = True
- else:
- print('Please enter A, S, D or M!!!')
- valid_operator = False
- print()
- print('Here is your answer:')
- print (N1 ,MO ,N2 ,'=' ,total)
- #FUNCTION: Number Averager
- def averages():
- a = 0
- n = 0
- a = float(input('What is your first number?'))
- n = n+1
- average = a/n
- #print ('The average is', average)
- end_loop = False
- while end_loop == False:
- another = str(input('Enter another number (y/n)?'))
- if another == 'y':
- b = float(input('What is your next number?'))
- a = a + b
- n = n+1
- average = a/n
- print ('You entered ' ,n , 'numbers and the average is', average)
- end_loop = False
- else:
- print ('You entered ' ,n , 'numbers and the average is', average)
- end_loop = True
- #FUNCTION: Select Maths Operation
- def Maths():
- print('This code performs simple maths operations on two numbers')
- 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: '))
- if option == '1':
- simple_maths()
- elif option == '2':
- SQ = int(input('Enter the number to square: '))
- A = SQ * SQ
- print(SQ, 'squared is: ', A)
- elif option == '3':
- SR = int(input('Enter the number to find the square root of: '))
- import math
- SRA = math.sqrt(SR)
- print('The square root of', SR, 'is', SRA)
- elif option == '4':
- averages()
- else:
- print ('OK then - Bye!!!!!')
- #Loop to perform multiple maths operations
- no_continue = False
- while no_continue == False:
- hello=input('Do you want to do some maths (Y / N)?')
- if hello == 'Y' or hello =='y':
- Maths()
- no_continue = False
- else:
- print ('Bye!!!')
- no_continue = True
Add Comment
Please, Sign In to add comment