Advertisement
Roddyn

bot_with_average

Dec 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. total = 0
  2. print("Hi, I am Marvin, your personal bot.")
  3.  
  4. #asks and prints users name
  5. user_name = input ("What is your name? ")
  6. print("Welcome " + user_name )
  7.  
  8. #input a calculation type
  9. command = input("How can I help? ")
  10.  
  11. #when input add does an addition calculation
  12. if command == "add":
  13. print("let's add some numbers")
  14. input1 = input("Number 1> ")
  15. input2 = input("Number 2> ")
  16. number1 = int(input1)
  17. number2 = int(input2)
  18. result = number1 + number2
  19. output = str(result)
  20. print(input1 + " + " + input2 + " = " + output)
  21.  
  22. #when input subtract does a suntraction calculation
  23. elif command == "subtract":
  24. print("let's subtract some numbers")
  25. input1 = input("Number 1> ")
  26. input2 = input("Number 2> ")
  27. number1 = int(input1)
  28. number2 = int(input2)
  29. result = number1 - number2
  30. output = str(result)
  31. print(input1 + " - " + input2 + " = " + output)
  32.  
  33. #when input multiply does a multiply calculation
  34. elif command == "multiply":
  35. print("let's Multiply some numbers")
  36. input1 = input("Number 1> ")
  37. input2 = input("Number 2> ")
  38. number1 = int(input1)
  39. number2 = int(input2)
  40. result = number1 * number2
  41. output = str(result)
  42. print(input1 + " * " + input2 + " = " + output)
  43.  
  44. #when input subtract does asubtraction calculation
  45. elif command == "subtract":
  46. print("let's subtract some numbers")
  47. input1 = input("Number 1> ")
  48. input2 = input("Number 2> ")
  49. number1 = int(input1)
  50. number2 = int(input2)
  51. result = number1 - number2
  52. output = str(result)
  53. print(input1 + " - " + input2 + " = " + output)
  54.  
  55. #when input triangle calculates the are of a right angled triangle
  56. elif command == "triangle":
  57. print("let's find the area of a right angled triangle")
  58. input1 = input("Base of the triangle> ")
  59. input2 = input("Height of the triangle> ")
  60. number1 = int(input1)
  61. number2 = int(input2)
  62. result = (number1 * 0.5) * number2
  63. output = str(result)
  64. print("(" + input1 + " * 0.5) *" + input2 + " = " + output)
  65. # if neither add or subtract outputs an apology
  66. elif command == "average":
  67. how_many = input("How many numbers> ")
  68. how_many = int(how_many)
  69. for number_count in range(how_many):
  70. number = input("Enter number " + str(number_count) + "> ")
  71. total = total + int(number)
  72. result = total / how_many
  73. print("the average = " + str(result))
  74. else:
  75. print ("sorry I can't do that yet!!!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement