Advertisement
Roddyn

aveage_total

Jan 26th, 2020
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 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":
  8. result = number1 + number2
  9. operator = " + "
  10. elif command == "subtract":
  11. result = number1 - number2
  12. operator = " - "
  13.  
  14. output = str(result)
  15. print(input1 + operator + input2 + " = " + output)
  16. def average_total():
  17. if command == "total":
  18. num = input("How many numbers> ")
  19. num = int(num)
  20. total=0
  21. for count in range(num):
  22. number = input("Enter number " +str(count+1) + "> ")
  23. total = total + int (number)
  24. result = total
  25. print("The total = " +str(result))
  26. elif command == "average":
  27. num = input("How many numbers> ")
  28. num = int(num)
  29. total=0
  30. for count in range(num):
  31. number = input("Enter number " +str(count+1) + "> ")
  32. total = total + int (number)
  33. result = total/num
  34. print("The average = " +str(result))
  35. total = 0
  36. meal_total=0
  37. cash=0
  38. finished=False
  39.  
  40.  
  41. while finished==False:
  42.  
  43. print("Hi, I am Marvin, your personal bot.")
  44.  
  45. #asks and prints users name
  46. user_name = input ("What is your name? ")
  47. print("Welcome " + user_name )
  48.  
  49. #input a calculation type
  50. command = input("How can I help? ")
  51.  
  52. #when input add does an addition calculation
  53. if command == "add":
  54. do_calculation()
  55.  
  56. #when input subtract does a suntraction calculation
  57. elif command == "subtract":
  58. do_calculation()
  59. elif command =="total":
  60. average_total()
  61. elif command == "average":
  62. average_total()
  63.  
  64. #when input multiply does a multiply calculation
  65. elif command == "multiply":
  66. print("let's Multiply some numbers")
  67. input1 = input("Number 1> ")
  68. input2 = input("Number 2> ")
  69. number1 = int(input1)
  70. number2 = int(input2)
  71. result = number1 * number2
  72. output = str(result)
  73. print(input1 + " * " + input2 + " = " + output)
  74.  
  75. #when input subtract does asubtraction calculation
  76. elif command == "subtract":
  77. print("let's subtract some numbers")
  78. input1 = input("Number 1> ")
  79. input2 = input("Number 2> ")
  80. number1 = int(input1)
  81. number2 = int(input2)
  82. result = number1 - number2
  83. output = str(result)
  84. print(input1 + " - " + input2 + " = " + output)
  85.  
  86. #when input triangle calculates the are of a right angled triangle
  87. elif command == "triangle":
  88. print("let's find the area of a right angled triangle")
  89. input1 = input("Base of the triangle> ")
  90. input2 = input("Height of the triangle> ")
  91. number1 = int(input1)
  92. number2 = int(input2)
  93. result = (number1 * 0.5) * number2
  94. output = str(result)
  95. print("(" + input1 + " * 0.5) *" + input2 + " = " + output)
  96. # if neither add or subtract outputs an apology
  97. elif command == "average":
  98. how_many = input("How many numbers> ")
  99. how_many = int(how_many)
  100. for number_count in range(how_many):
  101. number = input("Enter number " + str(number_count) + "> ")
  102. total = total + int(number)
  103. result = total / how_many
  104. print("the average = " + str(result))
  105. elif command == "change":
  106. meal = []
  107. count= 0
  108. meal_items=int(input("How many items in your meal list?" ))
  109.  
  110.  
  111. for item_number in range(meal_items):
  112. item = int(input("How much was your first item? " + str(meal_items)+""))
  113. meal.append(item)
  114. count= count +1
  115. meal_total=int(meal_total)+int(item)
  116.  
  117.  
  118. output = str(count)
  119.  
  120. print(meal)
  121.  
  122. print("You have spent " + str(meal_total) + " on your meal.")
  123.  
  124. cash= int(input("How much cash have you given?"))
  125.  
  126. leftover = int(cash)-int(meal_total)
  127. print(("You should receive $" +str(leftover)+" in your change!"))
  128.  
  129. elif command == "bye":
  130. finished = True
  131.  
  132.  
  133. else:
  134. print ("sorry I can't do that yet!!!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement