Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #the following three print commands display a message upon launch
- print("Hi, I am Marvin, your personal bot.")
- print("I hope you are feeling well today.")
- print("OK, let's get started...")
- #this next step requires the user to input their name
- users_name = input ("What's your name? ")
- #the following print command displays the inputted text from the user
- #along with a welcome
- print("Welcome " + users_name + "!")
- #the next command asks what mathematical operation the user requires
- #with different code for adding, subtracting, multiplying
- #and dividing(if and elif functions)
- command = input("What can I do for you? >")
- if command == "add" or command == "plus" or command == "+":
- print("Let's add some numbers!")
- input1 = input("Number 1 > ")
- input2 = input("Number 2 > ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 + number2
- output = str(result)
- print(input1 + " + " + input2 + " = " + output)
- elif command == "subtract" or command == "take away" or command == "-":
- print("Let's subtract some numbers!")
- input1 = input("Number 1 > ")
- input2 = input("Number 2 > ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 - number2
- output = str(result)
- print(input1 + " - " + input2 + " = " + output)
- elif command == "multiply" or command == "times" or command == "x":
- print("Let's mulitply some numbers!")
- input1 = input("Number 1 > ")
- input2 = input("Number 2 > ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 * number2
- output = str(result)
- print(input1 + " x " + input2 + " = " + output)
- elif command == "divide" or command == "share" or command == "/":
- print("Let's divide some numbers!")
- input1 = input("Number 1 > ")
- input2 = input("Number 2 > ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 / number2
- output = str(result)
- print(input1 + " / " + input2 + " = " + output)
- elif command == "area":
- print("Let's find the area of a rectangle.")
- input1 = input("Length of longer side in cm > ")
- input2 = input("Length of shorter side in cm > ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 * number2
- output = str(result)
- print("The area is " + input1 + "cm x " + input2 + "cm = " + output + "cm^2")
- elif command == "volume":
- print("OK. How about the volume of a cuboid?")
- input3 = input("Length of cuboid in cm > ")
- input4 = input("Height of cuboid in cm > ")
- input5 = input("Width of cuboid in cm > ")
- number3 = int(input3)
- number4 = int(input4)
- number5 = int(input5)
- result1 = number3 * number4 * number5
- output1 = str(result1)
- print("The volume is " + input3 + "cm x " + input4 + "cm x " + input5 + "cm = " + output1 + "cm^3")
- #the final "else" function displays a message if the required
- #command does not match any of those stated in the code above
- else:
- print("I'm sorry, I don't understand...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement