Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.94 KB | None | 0 0
  1. #define a function
  2. def do_calculation():
  3.     print("lets " + command + " some numbers")
  4.     input1 = input("Number 1 = ")
  5.     input2 = input("Number 2 = ")
  6.     number1 = int(input1)
  7.     number2 = int(input2)
  8.     #user asks bot to add
  9.     if command == "add" or command == "plus" or command == "+":
  10.         result = number1 + number2
  11.         operator = " + "
  12.     #user asks bot to subtract
  13.     elif command == "subtract" or command == "take away" or command == "takeaway" or command == "minus":
  14.         result = number1 - number2
  15.         operator = " - "
  16.     #user asks bot to multiply
  17.     elif command == "multiply" or command == "times":
  18.         result = number1 * number2
  19.         operator = " * "
  20.     #user asks bot to divide
  21.     elif command == "divide":
  22.         result = number1 / number2
  23.         operator = " / "
  24.     output = str(result)
  25.     print(input1 + operator + input2 + " = " +output)
  26.  
  27.  
  28.     #conditional loop
  29. print("Hi, I'm Marvin, your personal bot")
  30. print("We are going to have some fun together.")
  31. guess = input("Firstly, I would like you to guess the band that I am thinking of... ")
  32. count = 1
  33. while guess != "andsoiwatchyoufromafar":
  34.     guess = input("wrong - guess again ")
  35.     count = count +1
  36. print("well done!")
  37. count = str(count)
  38. print("It took you " + count + " attempts to get the correct answer.")
  39.  
  40. finished = False
  41. while finished == False:
  42.     print("Now we can do some calcuations. What would you like to do?")
  43.     command = input("Add? Subtract? Multiply? Divide? Find an average? Total a set of numbers? Write your shopping list? Find out how much you owe at the restaurant?")
  44.         #user specifies what they would like bot to do.
  45.     if command == "add" or command == "plus" or command == "+":
  46.         do_calculation()
  47.     elif command == "subtract" or command == "take away" or command == "takeaway" or command == "minus":
  48.         do_calculation()
  49.     elif command == "multiply" or command == "times":
  50.         do_calculation()
  51.     elif command == "divide":
  52.         do_calculation()
  53.  
  54. #user asks to calculate an average
  55.     elif command == "average":
  56.         how_many = input("How many numbers? ")
  57.         how_many = int(how_many)
  58.         total = 0
  59.         for number_count in range(how_many):
  60.             number = input("Enter number " + str(number_count+1) + ": ")
  61.             total = total + int(number)
  62.         result = total / how_many
  63.         print("The average of these numbers is " + str(result))
  64.     elif command == "shopping":
  65.         shopping = []
  66.         how_many = input ("How many items of shopping do you need to get? ")
  67.         how_many = int(how_many)
  68.         for item_number in range(how_many):
  69.             item = input("what is item number " +str(item_number+1) +"? ")
  70.             shopping.append(item)
  71.         print(shopping)
  72.         for item in shopping:
  73.             print(item)
  74.         output =str(len(shopping))
  75.         print("There are " + output + " items in your shopping list")
  76.     elif command == "restaurant":
  77.         how_many = input("How many diners? ")
  78.         how_many = int(how_many)
  79.         total = input ("How much is the total bill? £")
  80.         total = int(total)
  81.         result = total / how_many
  82.         result = int(result)
  83.         print("You each owe £" + str(result))
  84.     elif command == "total":
  85.         total = 0
  86.         how_many = input("How many numbers do you have? ")
  87.         how_many = int(how_many)
  88.         for number in range(how_many):
  89.             number = input("What is the number? ")
  90.             number = int(number)
  91.             total = total + number
  92.         print("Your total is " + str(total))
  93.         total = int(total)
  94.         print("The mean average is " + str(total/how_many))
  95.     elif command == "bye":
  96.         finished=True
  97.         print("It was great to talk to you. Thanks. See you again soon. Bye!")
  98.     else:
  99.         print(" Sorry I don't understand")
  100.         print("If I can't help you any more then please be polite and say bye.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement