Advertisement
Questor

Untitled

Aug 26th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. keep_running = True
  2. count = 0
  3.  
  4. def do_calculation():
  5.  
  6. # function to remove duplicated lines of code from add and subtract conditions
  7. print("Lets " + command + " some numbers.")
  8. input1 = input("Number 1> ")
  9. input2 = input("Number 2> ")
  10. number1 = float(input1)
  11. number2 = float(input2)
  12.  
  13. if command == "add" or command == "Add":
  14. operator = "+"
  15. result = number1 + number2
  16.  
  17. elif command == "subtract" or command == "Subtract":
  18. operator = "-"
  19. result = number1 - number2
  20.  
  21. # print the result to the screen
  22. output = str(result)
  23. print(input1 + " operator " + input2 + " = " + output)
  24.  
  25.  
  26. print ("Hi, I am Marvin, your personal bot.")
  27. print()
  28. users_name = input("Please enter your name : ") #ask for users name
  29.  
  30. while keep_running == True:
  31.  
  32. # print ("Hi, I am Marvin, your personal bot.")
  33. # print()
  34. # users_name = input("Please enter your name : ") #ask for users name
  35. print ("Hi " + users_name + ". I hope you enjoy using the bot.")
  36. print ("This bot will allow you to do simple mathematical procedures.")
  37. #command = input("So " + users_name + ", Would you like to 1 Add, 2 Subtract, 3 Divide, 4 Multiply, 5 find the Average of some numbers, or 6 create a Shopping List : ")
  38. command = input("So " + users_name + ", Would you like to Add, Subtract, Divide, Multiply, find the Average of some numbers, \n create a Shopping List or enter to end : ")
  39. # all numbers are floating point just in case decimals are needed
  40.  
  41. if command == "add" or command == "Add" or command == "plus" or command == "Plus" :
  42. #add 2 numbers together
  43.  
  44. do_calculation()
  45.  
  46.  
  47. elif command == "subtract" or command == "Subtract" or command == "minus" or command == "Minus":
  48. #subtract 2 numbers from each other
  49.  
  50. do_calculation()
  51.  
  52. #print("Lets subtract some numbers from each other.")
  53. #input1 = input("Number 1> ")
  54. #input2 = input("Number 2> ")
  55. #number1 = float(input1)
  56. #number2 = float(input2)
  57. #result = number1 - number2
  58. #output = str(result)
  59. #print(input1 + " - " + input2 + " = " + output)
  60.  
  61.  
  62. elif command == "multiply" or command == "Multiply":
  63. #multiply 2 numbers by each other
  64. print("Lets multiply some numbers together.")
  65. input1 = input("Number 1> ")
  66. input2 = input("Number 2> ")
  67. number1 = float(input1)
  68. number2 = float(input2)
  69. result = number1 * number2
  70. output = str(result)
  71. print(input1 + " * " + input2 + " = " + output)
  72.  
  73.  
  74. elif command == "divide" or command == "Divide":
  75. #divide 2 numbers with each other
  76. print("Lets " + command + " some numbers.")
  77. input1 = input("Number 1> ")
  78. input2 = input("Number 2> ")
  79. number1 = float(input1)
  80. number2 = float(input2)
  81. result = number1 / number2
  82. output = str(result)
  83. print(input1 + " / " + input2 + " = " + output)
  84.  
  85.  
  86. elif command == "average" or command == "Average":
  87. #find the average of several numbers
  88. print("Lets find the " + command + " of some numbers.")
  89. print(command + " has just been implemented. So here we go.")
  90. # Numcount = input("how many number would you like to average? > ")
  91.  
  92. how_many = input("How many numbers? } ")
  93. how_many = int(how_many)
  94. Avelist = []
  95.  
  96. total = 0
  97. for number_count in range (how_many):
  98. Avenumber = input("Enter number " + str(number_count) + " } ")
  99. total = total + float(Avenumber)
  100. Avelist.append(Avenumber)
  101.  
  102. result =total / how_many
  103. result = result
  104.  
  105. for Avenumber in Avelist:
  106. print(Avenumber)
  107.  
  108. print("The average of the numbers above = " + str(result))
  109.  
  110.  
  111. elif command == "Shopping List" or command == "shopping list" or command == "Shopping list" or command == "shopping List":
  112. # shopping list creator
  113. shopping = [] #holds the shoopping items
  114. itemprice = [] # contains the item cost
  115. total_sum = 0 #variable for the total cost of the shopping items
  116. keep_shopping = True
  117. num = 0 #vriable for total number if items
  118. total_sum = 0
  119. while keep_shopping == True:
  120.  
  121. #set up using a while statement to collect items until bye entered by user
  122. item = input("enter the item name or bye to finish : ")
  123.  
  124. # ends the loop
  125. if item == "bye" or item == "Bye":
  126. keep_shopping = False
  127. continue
  128.  
  129. shopping.append(item)
  130. price = input("enter the item price : ")
  131. itemprice.append(price)
  132.  
  133. total_sum = total_sum + float((price))
  134. num = num +1
  135. print("Total shopping cost so far : " + str(total_sum) + " for : " + str(num) + " items")
  136.  
  137.  
  138.  
  139. # prints the shopping list and total cost
  140. print ("Shopping list\n")
  141. for item_number in range(num):
  142.  
  143. print (shopping[item_number] + "\t\t\t" + itemprice[item_number] )
  144.  
  145. print ("------------------------------------")
  146. print ("Total cost \t\t$" + str(total_sum)+ " for : " + str(num) + " items")
  147.  
  148.  
  149. else: #just in case they did not choose one of the options
  150. print("Sorry " + users_name + " but the bot can only Add, Subtract, Divide, Multiply, find the Average of numbers or creater a Shopping list")
  151. print("Cheers " + users_name)
  152. print()
  153. print("Hey " + users_name + ", thanks for using the Mathematics and Shopping list creator bot. Cheers Marvin.")
  154.  
  155. if command == "":
  156. keep_running = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement