Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. def do_calculation1():
  2.     print("lets " + z + " some numbers")
  3.     input1 = input("Number 1> ")
  4.     input2 = input("Number 2> ")
  5.     number1 = int(input1)
  6.     number2 = int(input2)
  7.     if z==('add') or z==('+'):
  8.         result = number1 + number2
  9.         operator='+'
  10.     elif z==('subtract') or z==('-'):
  11.         result = number1 - number2
  12.         operator='-'
  13.     elif z==('multiply') or z==('*'):
  14.         result = number1 * number2
  15.         operator='*'
  16.     elif z==('divide') or z==('/'):
  17.         result = number1 / number2
  18.         operator='/'
  19.     output = str(result)
  20.     print(input1 + operator + input2 + " = " + output)
  21.  
  22.  
  23. ask=False #or without it
  24. while ask==False: #or while True:
  25.     z= input('do you want to add, subtract, multiply, divide, find the average or total ? ')
  26.     if z==('add') or z==('+'):
  27.         do_calculation1()
  28.     elif z==('subtract') or z==('-'):
  29.         do_calculation1()
  30.     elif z==('multiply') or z==('*'):
  31.         do_calculation1()
  32.     elif z==('divide') or z==('/'):
  33.         do_calculation1()
  34.     elif z==('average') or z==('total'):
  35.         how=input("how many numbers? ")
  36.         how=int(how)
  37.         total=0
  38.         for count in range(how):
  39.             number=input('enter number '+ str(count)+ ': ')
  40.             number=int(number)
  41.             total=total+number
  42.         if z==('total'):
  43.            print('Total=', total)
  44.         elif z==('average'):
  45.             r=total/how
  46.             print('Average=', total, '÷', how, '=', r)
  47.     elif z=='bye':
  48.         ask=True #or break
  49.     else: print('not identified')
  50.     print('done!')
  51. print('** see you later **')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement