Advertisement
Pedroleon

add_substract_divide_multiply and AVERAGE, shoppinlist,area

Jan 13th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. print("Hi, I am Marvin, your personal bot.")
  2. phrase = input("Whats your name ? >")
  3. print(" Morning " + phrase)
  4. print("Do you want to divide, multiply , add, substract , average, shopping list, area ?")
  5. command = input("How can I help ? >")
  6. if command == "divide" or command == "plus":
  7. print("Let's divide 2 numbers.")
  8. input1 = input("Number 1> ") # input numbers are strings#
  9. input2 = input("Number 2> ")
  10. number1 = int(input1) # use int to convert string to integer#
  11. number2 = int(input2)
  12. result = number1 / number2 # by using add #
  13. output = str(result) # result of operation#
  14. print(input1 + " / " + input2 + " = " + output)
  15. elif command == "multiply":
  16. print(" Let's multiply 2 numbers.")
  17. input1 = input("Number 1> ")
  18. input2 = input("Number 2> ")
  19. number1 = int(input1)
  20. number2 = int(input2)
  21. result = number1 * number2
  22. output = str(result)
  23. print(input1 + " * " + input2+" = " + output)
  24. elif command == "add":
  25. print(" Let's add 2 numbers.")
  26. input1 = input("Number 1> ")
  27. input2 = input("Number 2> ")
  28. number1 = int(input1)
  29. number2 = int(input2)
  30. result = number1 + number2
  31. output = str(result)
  32. print(input1 + " + " + input2+" = " + output)
  33. elif command == "substract":
  34. print(" Let's substract 2 numbers.")
  35. input1 = input("Number 1> ")
  36. input2 = input("Number 2> ")
  37. number1 = int(input1)
  38. number2 = int(input2)
  39. result = number1 - number2
  40. output = str(result)
  41. print(input1 + " - " + input2+" = " + output)
  42.  
  43.  
  44. elif command == "average":
  45. print("NOW find average")
  46. how_many = input("How many numbers > ")
  47. how_many = int(how_many)
  48. total = 0
  49. for number_count in range(how_many):
  50. number = input("Enter number " + str(number_count) + "?")
  51. total = total + int(number)
  52. result = total /how_many
  53. print("the average = " + str(result))
  54. elif command == "area":
  55. print("Let's find the area of a rectangle.")
  56. input1 = input("Enter the width:")
  57. input2 = input("Enter the height: ")
  58. number1 = int(input1)
  59. number2 = int(input2)
  60. result = number1 * number2
  61. output = str(result)
  62. print("The area of a " + input1 + " by " + input2 + " rectangle is = " + output)
  63.  
  64. elif command == "shopping list":
  65. print ("Now let's go shopping")
  66. shopping = []
  67. total_cost = 0
  68. how_many = input("how many items in your list ?")
  69. how_many = int(how_many)
  70.  
  71. for item_number in range(how_many):
  72. item = input("What is item number " + str(item_number + 1) + "?")
  73. cost = input("What does " + item + " cost in euros? >")
  74. cost = float(cost)
  75. shopping.append(item)
  76. total_cost = total_cost + cost
  77. print(" You have to pay " + str(total_cost))
  78. else:
  79. print("Sorry I don't understand")
  80. print("Well done" + phrase)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement