Advertisement
Roddyn

while if

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