Advertisement
Roddyn

bot_while_if

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