Advertisement
dlbieber

Python math bot with added average/total function

Dec 14th, 2018
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. def intro():
  2. print("Lets do some coding!")
  3.  
  4. def doAddSub(command):
  5. print("lets " + command + " some numbers")
  6. input1 = input("Number 1> ")
  7. input2 = input("Number 2> ")
  8. number1 = int(input1)
  9. number2 = int(input2)
  10. if command == "add":
  11. result = number1 + number2
  12. operator = " + "
  13. elif command == "subtract":
  14. result = number1 - number2
  15. operator = " - "
  16. output = str(result)
  17. print (input1 + operator + input2 + " = " + output)
  18.  
  19. def doAvgTot(command):
  20. # Data collection - include running total
  21. input1 = input( "Enter the number of numbers you would like to " + command + ": ")
  22. n = int(input1)
  23. i = 0
  24. total = 0
  25. for i in range(n):
  26. num = input("Enter number " + str(i) +": ")
  27. total += int(num)
  28.  
  29. if command == "average": # Calculate average
  30. result = total / n
  31. else:
  32. result = total
  33.  
  34. # Provide results to user
  35. print ("The average of your numbers is: " + str(result) + ".")
  36. finished = False
  37.  
  38. while finished==False:
  39. phrase = input ("Talk to me > ")
  40. total = 0
  41. if phrase == "hi" or phrase == "hey" or phrase == "hello":
  42. print( "hello")
  43. elif phrase == "whats your name" or phrase == "what's your name":
  44. print("Marvin")
  45. elif phrase == "exit" or phrase == "quit":
  46. exit;
  47. elif phrase == "quiz":
  48. while phrase != "exit" and phrase != "quit":
  49. phrase = input("What is 1 + 3? ")
  50. if int(phrase) == 4:
  51. print ("Correct!")
  52. break
  53. else:
  54. print ("Incorrect - please try again!")
  55. elif phrase == "average" or phrase == "total":
  56. doAvgTot(phrase)
  57.  
  58. elif phrase == "discount":
  59. discount = int( input("Please enter the percentage discount: "))
  60. cost = int( input( "Please enter the item(s) cost: "))
  61. print ("disc: " + str(discount) + " cost: " + str(cost) + " tot: " + str(total))
  62. total = cost - (float(discount)*float(cost)/100)
  63. print("Your " + str(discount) + "% discount of " + str(cost) + " is: " + str(total))
  64. elif phrase == "add" or phrase == "subtract":
  65. doAddSub(phrase)
  66. elif phrase == "bye":
  67. finished = True
  68. else:
  69. print( "Sorry, I don't understand " + "'" + phrase +"'.")
  70.  
  71. print ("bye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement