Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define a function
- def do_calculation():
- print("lets " + command + " some numbers")
- input1 = input("Number 1 = ")
- input2 = input("Number 2 = ")
- number1 = int(input1)
- number2 = int(input2)
- #user asks bot to add
- if command == "add" or command == "plus" or command == "+":
- result = number1 + number2
- operator = " + "
- #user asks bot to subtract
- elif command == "subtract" or command == "take away" or command == "takeaway" or command == "minus":
- result = number1 - number2
- operator = " - "
- #user asks bot to multiply
- elif command == "multiply" or command == "times":
- result = number1 * number2
- operator = " * "
- #user asks bot to divide
- elif command == "divide":
- result = number1 / number2
- operator = " / "
- output = str(result)
- print(input1 + operator + input2 + " = " +output)
- #conditional loop
- print("Hi, I'm Marvin, your personal bot")
- print("We are going to have some fun together.")
- guess = input("Firstly, I would like you to guess the band that I am thinking of... ")
- count = 1
- while guess != "andsoiwatchyoufromafar":
- guess = input("wrong - guess again ")
- count = count +1
- print("well done!")
- count = str(count)
- print("It took you " + count + " attempts to get the correct answer.")
- finished = False
- while finished == False:
- print("Now we can do some calcuations. What would you like to do?")
- 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?")
- #user specifies what they would like bot to do.
- if command == "add" or command == "plus" or command == "+":
- do_calculation()
- elif command == "subtract" or command == "take away" or command == "takeaway" or command == "minus":
- do_calculation()
- elif command == "multiply" or command == "times":
- do_calculation()
- elif command == "divide":
- do_calculation()
- #user asks to calculate an average
- elif command == "average":
- how_many = input("How many numbers? ")
- how_many = int(how_many)
- total = 0
- for number_count in range(how_many):
- number = input("Enter number " + str(number_count+1) + ": ")
- total = total + int(number)
- result = total / how_many
- print("The average of these numbers is " + str(result))
- elif command == "shopping":
- shopping = []
- how_many = input ("How many items of shopping do you need to get? ")
- how_many = int(how_many)
- for item_number in range(how_many):
- item = input("what is item number " +str(item_number+1) +"? ")
- shopping.append(item)
- print(shopping)
- for item in shopping:
- print(item)
- output =str(len(shopping))
- print("There are " + output + " items in your shopping list")
- elif command == "restaurant":
- how_many = input("How many diners? ")
- how_many = int(how_many)
- total = input ("How much is the total bill? £")
- total = int(total)
- result = total / how_many
- result = int(result)
- print("You each owe £" + str(result))
- elif command == "total":
- total = 0
- how_many = input("How many numbers do you have? ")
- how_many = int(how_many)
- for number in range(how_many):
- number = input("What is the number? ")
- number = int(number)
- total = total + number
- print("Your total is " + str(total))
- total = int(total)
- print("The mean average is " + str(total/how_many))
- elif command == "bye":
- finished=True
- print("It was great to talk to you. Thanks. See you again soon. Bye!")
- else:
- print(" Sorry I don't understand")
- 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