Advertisement
sjzmilton

Untitled

Dec 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. def do_calculation():
  2. print("lets " + command + " some numbers")
  3. input1 = input("Number 1> ")
  4. input2 = input("Number 2> ")
  5. number1 = int(input1)
  6. number2 = int(input2)
  7. if command == "add" or command == "plus":
  8. result = number1 + number2
  9. operator = " + "
  10. elif command == "subtract" or command == "minus":
  11. result = number1 - number2
  12. operator = " - "
  13. elif command == "multiply" or command == "times":
  14. result = number1 * number2
  15. operator = " * "
  16. elif command == "divide" or command == "division":
  17. result = number1 / number2
  18. operator = " / "
  19. output = str(result)
  20. print(input1 + operator + input2 + " = " + output)
  21.  
  22. def Add_Them_Up():
  23. total = 0
  24. how_many = input("how many numbers would you like to enter? ")
  25. how_many = int(how_many)
  26. for item_number in range(how_many):
  27. number = input("Enter the number of " + str(item_number) + "> ")
  28. total = total + int(number)
  29. if command == "total":
  30. print("You have entered " + str(how_many) + " numbers. Your total is " + str(total))
  31. elif command == "average" or command == "avg":
  32. avg = total / int(how_many)
  33. print("You have entered " + str(how_many) + " numbers. Your average is " + str(avg))
  34.  
  35. finished = False
  36. while finished == False:
  37. print("Hi, I am Zed, your personal bot.")
  38. command = input("How can I help (bye to end program)? ")
  39. if command == "add" or command == "plus":
  40. do_calculation()
  41. elif command == "subtract" or command == "minus":
  42. do_calculation()
  43. elif command == "multiply" or command == "times":
  44. do_calculation()
  45. elif command == "divide" or command == "division":
  46. do_calculation()
  47. elif command == "Area":
  48. print("lets calculate the area of a triangle")
  49. input1 = input("Base > ")
  50. input2 = input("Hypotenuse > ")
  51. number1 = int(input1)
  52. number2 = int(input2)
  53. result = (number1 * number2) / 2
  54. output = str(result)
  55. print("(Base:"+input1 + " * " + "Hypotenuse:"+input2 + ") / 2" + " = " + output)
  56. elif command == "average" or command == "avg":
  57. total = 0
  58. how_many = input("how many numbers? ")
  59. how_many = int(how_many)
  60. for number_count in range(how_many):
  61. number = input("Enter number " + str(number_count) + "> ")
  62. total = total + int(number)
  63. result = total / how_many
  64. print("the average = " + str(result))
  65. elif command == "shopping" or command == "shop":
  66. total = 0
  67. shopping = []
  68. how_many = input("how many items of shopping do you have? ")
  69. how_many = int(how_many)
  70. for item_number in range(how_many):
  71. item = input("what is the item " + str(item_number) + " ? ")
  72. number = input("Enter the cost of " + str(item) + "> ")
  73. total = total + int(number)
  74. shopping.append(item)
  75. print(shopping)
  76. print("You have " + str(how_many) + " items in your shopping list. Your total is " + str(total))
  77. elif command == "total":
  78. Add_Them_Up()
  79. elif command == "average" or "avg":
  80. Add_Them_Up()
  81. elif command == "bye":
  82. finished = True
  83. else:
  84. print("sorry I dont understand")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement