Advertisement
Mori007

BotWhile

May 4th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. finished = False
  2.  
  3. def do_calculation():
  4. print("lets " + command + " some numbers")
  5. input1 = input("Number 1>")
  6. input2 = input("Number 2>")
  7. number1 = int(input1)
  8. number2 = int(input2)
  9. if command == "add":
  10. result = number1 + number2
  11. elif command == "subtract":
  12. result = number1 - number2
  13. output = str(result)
  14. if command == "add":
  15. print(input1 + " + " + input2 + " = " + output)
  16. elif command == "subtract":
  17. print(input1 + " - " + input2 + " = " + output)
  18.  
  19. def do_averege():
  20. how_many = input("How many numbers> ")
  21. how_many = int(how_many)
  22. total = 0
  23. for number_count in range(how_many):
  24. number = input("Enter number " + str(number_count) + "> ")
  25. total = total + int(number)
  26. result = total / how_many
  27. print("the average = " + str(result))
  28.  
  29. def do_total():
  30. how_many = input("How many numbers> ")
  31. how_many = int(how_many)
  32. total = 0
  33. for number_count in range(how_many):
  34. number = input("Enter number " + str(number_count) + "> ")
  35. total = total + int(number)
  36. result = total
  37. print("the average = " + str(result))
  38.  
  39. print("Hi, I am Marvin, your personal bot.")
  40.  
  41. while finished == False:
  42. command = input("How can I help? ")
  43. if command == "add":
  44. do_calculation()
  45. elif command == "subtract":
  46. do_calculation()
  47. elif command == "multiply":
  48. do_calculation()
  49. elif command == "divide":
  50. do_calculation()
  51. elif command == "average":
  52. do_average()
  53. elif command == "total":
  54. do_total()
  55. elif command == "bye":
  56. finished = True
  57. else:
  58. print("sorry I dont understand")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement