SHARE
TWEET

Untitled

a guest Aug 19th, 2019 87 in 149 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # On to adding more options for the bot from last week:
  2. import operator
  3.  
  4. ops = {"+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv}
  5.  
  6.  
  7. def do_calculation():
  8.     print(f"lets {command} some numbers!")
  9.     number1 = int(input("Number 1> "))
  10.     number2 = int(input("Number 2> "))
  11.     operation = calculation_dict[command]
  12.     result = ops[operation](number1, number2)
  13.     output = str(result)
  14.     print(f"{number1} {operation} {number2} = {output}")
  15.  
  16.  
  17. finished = False
  18.  
  19. while finished == False:
  20.     print("Hi, I am Marvin, your personal bot.")
  21.     command = input("How can I help? ")
  22.     calculation_dict = {"add" : "+" , "plus" : "+" , "subtract" : "-" , "minus" : "-" , "multiply" : "*" , "divide" : "/" }
  23.     if command in calculation_dict:
  24.         do_calculation()
  25.     elif command == "average":
  26.         print("lets average some numbers!")
  27.         numbers = []
  28.         how_many = input("How many numbers would you like to average? ")
  29.  
  30.         for number in range(int(how_many)):
  31.             item = input(f"What is the {number + 1} number? ")
  32.             numbers.append(int(item))
  33.             print(f"{item} has been selected as the {number + 1} number to average")
  34.  
  35.         average_numbers = sum(numbers) / len(numbers)
  36.  
  37.         print(
  38.             f"The {len(numbers)} numbers you entered have an average value of {average_numbers}."
  39.         )
  40.     elif command == "bye":
  41.         finished = True
  42.         print("Fine, I'm bored too!")
  43.     else:
  44.         print(f"I'm sorry, I don't understand '{command}'.")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top