Advertisement
Guest User

bot@ShaunW

a guest
May 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. #FutureLearn Python 101 - Silly the Math Bot
  2. print("Hi, I am Silly, your personal math bot")
  3. print("I am here to assist. Now lets get started!")
  4. users_name = input("Please enter your name")
  5. print("Welcome, " + users_name + ".")
  6.  
  7. #do_calculation_plus_times() function for add, mult
  8. def do_calculation_plus_times():
  9. print("Lets " + command + " some numbers...")
  10. how_many = input("How many numbers will you " + command + ">")
  11. how_many = int(how_many)
  12. total_add = 0
  13. total_multiply = 1
  14. for num_count in range(how_many):
  15. number = input("Enter number " + str(num_count + 1) + ">")
  16. if command == "add" or command == "+":
  17. total_add = total_add + float(number)
  18. output = str(total_add)
  19. elif command == "multiply" or command == "*" or command == "x":
  20. total_multiply = total_multiply * float(number)
  21. if command == "add" or command == "+":
  22. output = str(total_add)
  23. elif command == "multiply" or command == "*" or command == "x":
  24. output = str(total_multiply)
  25. print("Your total = " + output)
  26.  
  27. #do_calculation_sub_div() function for subtract/divide
  28. def do_calculation_sub_div():
  29. print("Lets " + command + " two numbers")
  30. input1 = input("Number 1>")
  31. input2 = input("Number 2>")
  32. number1 = float(input1)
  33. number2 = float(input2)
  34. if command == "subtract" or command == "-":
  35. operator = " - "
  36. result = (number1 - number2)
  37. elif command == "divide" or command == "/" or command == "div":
  38. operator = " / "
  39. result = (number1 / number2)
  40. output = str(result)
  41. print(input1 + operator + input2 + " = " + output)
  42.  
  43. #do_calculation_total_avg() function for totals and averages
  44. def do_calculation_total_avg():
  45. print("Lets " + command + " some numbers...")
  46. how_many = input("How many numbers will you " + command + ">")
  47. how_many = int(how_many)
  48. total = 0
  49. list_numbers = []
  50. for num_count in range(how_many):
  51. number = input("Enter number " + str(num_count + 1) + ">")
  52. list_numbers.append(number)
  53. total = total + int(number)
  54. if command == "average" or command == "avg" or command == "%":
  55. result = int(total / how_many)
  56. elif command == "total":
  57. result = int(total)
  58. print("Your numbers: " + str(list_numbers))
  59. print("Your " + command + " = " + str(result))
  60.  
  61. #start program
  62. quit = False
  63. while quit == False:
  64. command = input("How can I help? (bye or q to quit)")
  65. #Addition with looping
  66. if command == "add" or command == "+":
  67. do_calculation_plus_times()
  68. #Subtraction
  69. elif command == "subtract" or command == "-":
  70. do_calculation_sub_div()
  71. #Multiplication with looping
  72. elif command == "multiply" or command == "*" or command == "x":
  73. do_calculation_plus_times()
  74. #Division
  75. elif command == "divide" or command == "/" or command == "div":
  76. do_calculation_sub_div()
  77. #Triangle Area Calculation
  78. elif command == "area":
  79. print("Lets calculate a triangle's area...")
  80. input1 = input("Triangle base>")
  81. input2 = input("Triangel height>")
  82. number1 = int(input1)
  83. number2 = int(input2)
  84. result = (number1 * number2)/2
  85. output = str(result)
  86. print("Triangle with base: " + input1 + " and height: " + input2 + " has an area of " + output)
  87. #Calculating Averages and Totals with looping
  88. elif command == "average" or command == "avg" or command == "%" or command == "total":
  89. do_calculation_total_avg()
  90. #Shopping List and Total Calculator with lists and loops
  91. elif command == "shopping" or command == "list" or command == "shopping list":
  92. shopping = []
  93. prices = []
  94. total = 0
  95. count = 0
  96. how_many = input("How many shopping items today? ")
  97. how_many = int(how_many)
  98. for item_num in range(how_many):
  99. item = input("Enter item nubmer " + str(item_num + 1) + ">")
  100. shopping.append(item)
  101. price = float(input("Enter its cost>"))
  102. prices.append(price)
  103. total += price
  104. count = count + 1
  105. total_items = str(count)
  106. count = 0
  107. for item_num in shopping:
  108. print(str(count+1) + ". " + shopping[count])
  109. count = count + 1
  110. print("You have " + total_items + " items in your shopping list")
  111. print("Those " + total_items + " items total cost is $" + str(total))
  112. #Cost of Meal Divider
  113. elif command == "meal divider" or command == "meal div":
  114. input1 = input("What is the total cost of the bill>")
  115. input2 = input("How many people are splitting the bill>")
  116. number1 = float(input1)
  117. number2 = int(input2)
  118. result = (number1 / number2)
  119. output = str(result)
  120. print("Total cost per person = " + output)
  121. elif command == "bye" or command == "q":
  122. quit = True
  123. else:
  124. print("Sorry " + users_name + ", I don't understand " + "'" + command + "'")
  125. print("Thank you, goodbye!")
  126. #end program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement