Advertisement
brendan-stanford

Bot

Aug 6th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. # Ask user for name and greet them.
  2. print("Hello, World!")
  3. users_name = input("Name: ")
  4. print("Hello, " + users_name + ".")
  5.  
  6. # Ask user to input command to add or subtract.
  7. command = input("operation?")
  8.  
  9. # Get two integers from user and add.
  10. if command == "add" or command == "addition":
  11. num1 = input("Number 1: ")
  12. n1 = int(num1)
  13. num2 = input("Number 2: ")
  14. n2 = int(num2)
  15. result = n1 + n2
  16. output = str(result)
  17. print(num1 + " + " + num2 + " = " + output)
  18.  
  19. # Get two integers from user and subtract.
  20. elif command == "sub" or command == "subtract" or command == "subtraction":
  21. num1 = input("Number 1: ")
  22. n1 = int(num1)
  23. num2 = input("Number 2: ")
  24. n2 = int(num2)
  25. result = n1 - n2
  26. output = str(result)
  27. print(num1 + " - " + num2 + " = " + output)
  28.  
  29. # Get two integers from user and multiply.
  30. elif command == "multiply" or command == "multiplication":
  31. num1 = input("Number 1: ")
  32. n1 = int(num1)
  33. num2 = input("Number 2: ")
  34. n2 = int(num2)
  35. result = n1 * n2
  36. output = str(result)
  37. print(num1 + " * " + num2 + " = " + output)
  38.  
  39. # Get two integers from user and divide.
  40. elif command == "divide" or command == "division":
  41. num1 = input("Number 1: ")
  42. n1 = int(num1)
  43. num2 = input("Number 2: ")
  44. n2 = int(num2)
  45. result = n1 / n2
  46. output = str(result)
  47. print(num1 + " / " + num2 + " = " + output)
  48.  
  49. # Get dimensions and calculate area.
  50. elif command == "Area" or command == "area":
  51. num1 = input("Length: ")
  52. n1 = int(num1)
  53. num2 = input("Width: ")
  54. n2 = int(num2)
  55. result = n1 * n2
  56. output = str(result)
  57. print(num1 + " * " + num2 + " = " + output)
  58.  
  59. # Get dimensions from user and calculate volume.
  60. elif command == "Volume" or command == "volume":
  61. num1 = input("Length: ")
  62. n1 = int(num1)
  63. num2 = input("Width: ")
  64. n2 = int(num2)
  65. num3 = input("Height: ")
  66. n3 = int(num3)
  67. result = n1 * n2 * n3
  68. output = str(result)
  69. print(num1 + " * " + num2 + " * " + num3 + " = " + output)
  70.  
  71. # Calculate average; get a list of numbers and size of list from user, then set total to 0
  72. elif command == "Average" or command == "mean":
  73. numbers = []
  74. size = input("Number of items to average:")
  75. size = int(size)
  76. total = 0
  77.  
  78. #input number from user and add to total
  79. for item_n in range(size):
  80. item = input("what is item " + str(item_n) + "?")
  81. numbers.append(item)
  82. value = int(item)
  83. total += value
  84.  
  85. #calculate average by dividing total by list size
  86. average = (total / size)
  87. mean = str(average)
  88. print("The average is " + mean)
  89.  
  90. # Calculalate tip based on price paid and desired percentage
  91. elif command == "tip" or command == "gratuity":
  92. price = input("Original price:")
  93. price = int(price)
  94. percent = input("What percent would you like to tip?")
  95. percent = (int(percent)/100)
  96. tip = price * percent
  97. tip = str(tip)
  98. print("Tip is " + tip)
  99.  
  100. # invalid input
  101. else:
  102. print("I don't understand " + "'" + command + "'")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement