Advertisement
GCK

GCK/other function tests_elaborated

GCK
Sep 16th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. def do_calculation_with_2_numbers():
  2.     print("lets "+ answer + " your numbers")
  3.     input1=input("enter number 1>")
  4.     input2=input("Enter number2>")
  5.     number1=int(input1)
  6.     number2=int(input2)
  7.     if answer=="substract":
  8.           result=number1-number2
  9.           operator="-"
  10.     elif answer=="add":
  11.          result=number1+number2
  12.          operator="+"
  13.     elif answer=="multiply":
  14.          result=(number1)*(number2)
  15.          operator="*"
  16.     print("Results for "+input1+ operator +input2 + "= "+str(result))
  17.  
  18.    
  19.    
  20.    
  21.    
  22.  
  23. finished=False
  24. print("Hello Im gigi your bot")
  25. print("let's get started for more practice")
  26. print("How can I help you?")
  27. while finished==False:
  28.     print("Would you like to make an operation?")
  29.     operation=input("Answer: type  Y or YES for YES and type N or NO for NO? >")
  30.    
  31.     if operation=="NO" or operation=="N":
  32.         print("Bye Bye")
  33.     elif operation=="YES" or operation=="Y":
  34.         answer=input("Do you want to : > ( substract, add, multiply, sum or average) ?>")
  35.         if answer=="substract" or answer=="add" or answer=="multiply":
  36.             do_calculation_with_2_numbers()          
  37.         elif answer=="sum" or answer=="average":
  38.             how_many=int(input("How many numbers>"))
  39.             total=0
  40.             Average=0
  41.             for number_count in range(how_many):
  42.                 number=input("Enter number "+ str(number_count)+ ":>)")
  43.                 total=total+ int(number)
  44.                 Average=total/how_many
  45.             if answer=="sum":
  46.                 print("Total cost is = " + str(total))
  47.             elif answer=="average":
  48.                 print("The average of "+ str(total)+ " by " + str(how_many) + "= "+str(Average))
  49.         else:
  50.             print("Try again. I don't understand")
  51.     elif operation=="bye":
  52.         print("Goodbye!")
  53.         finished=True
  54.        
  55.     else:
  56.         print("I dont understand '"+ operation + " )'")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement