Advertisement
DEP21

Untitled

May 26th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. def do_calculation():
  2. input1 = input("Input number 1 ")
  3. input2 = input("Input number 2 ")
  4. number1 = int(input1)
  5. number2 = int(input2)
  6. if command == "+":
  7. result = number1 + number2
  8. print ("Result is " + str(result))
  9.  
  10. elif command == "-":
  11. result = number1 - number2
  12. print ("Result is " + str(result))
  13. elif command == "x":
  14. result = number1 * number2
  15. print ("Result is " + str(result))
  16. elif command == "/":
  17. result = number1 / number2
  18. operator = "/ "
  19. output = str(result)
  20. print(input1 + operator + input2 + " = " + output)
  21. def do_average():
  22. how_many = input("How many numbers? ")
  23. how_many = int(how_many)
  24. total = 0
  25. for number_count in range(how_many):
  26. number = input("Enter number " + str(number_count) + " ")
  27. total = total + int(number)
  28. output = total/how_many
  29. print("The average = " + str(output))
  30.  
  31. finished = False
  32. while finished == False:
  33. print ("Hi, I am Doris your personal Bot.")
  34. command = input("What would you like to do - add (+), subtract (-), multiply (x), divide (/)or average (aver)? ")
  35. if command == "add" or command == "+":
  36. do_calculation()
  37. elif command == "subtract" or command == "-":
  38. do_calculation()
  39. elif command == "multiply" or command == "x":
  40. do_calculation()
  41. elif command == "divide" or command == "/":
  42. do_calculation()
  43. elif command == "average" or command == "aver":
  44. do_average()
  45. elif command == "bye":
  46. finished = True
  47. print ("Goodbye")
  48.  
  49. else:
  50. print("Sorry I don't understand")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement