Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def do_calculation():
- print("lets " + command + " some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- if command == "add":
- result = number1 + number2
- operator = " + "
- elif command == "subtract":
- result = number1 - number2
- operator = " - "
- output = str(result)
- print(input1 + operator + input2 + " = " + output)
- total = 0
- meal_total=0
- cash=0
- finished=False
- while finished==False:
- print("Hi, I am Marvin, your personal bot.")
- #asks and prints users name
- user_name = input ("What is your name? ")
- print("Welcome " + user_name )
- #input a calculation type
- command = input("How can I help? ")
- #when input add does an addition calculation
- if command == "add":
- do_calculation()
- #when input subtract does a suntraction calculation
- elif command == "subtract":
- do_calculation()
- #when input multiply does a multiply calculation
- elif command == "multiply":
- print("let's Multiply 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)
- #when input subtract does asubtraction calculation
- elif command == "subtract":
- 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)
- #when input triangle calculates the are of a right angled triangle
- elif command == "triangle":
- print("let's find the area of a right angled triangle")
- input1 = input("Base of the triangle> ")
- input2 = input("Height of the triangle> ")
- number1 = int(input1)
- number2 = int(input2)
- result = (number1 * 0.5) * number2
- output = str(result)
- print("(" + input1 + " * 0.5) *" + input2 + " = " + output)
- # if neither add or subtract outputs an apology
- elif command == "average":
- how_many = input("How many numbers> ")
- how_many = int(how_many)
- for number_count in range(how_many):
- number = input("Enter number " + str(number_count) + "> ")
- total = total + int(number)
- result = total / how_many
- print("the average = " + str(result))
- elif command == "change":
- meal = []
- count= 0
- meal_items=int(input("How many items in your meal list?" ))
- for item_number in range(meal_items):
- item = int(input("How much was your first item? " + str(meal_items)+""))
- meal.append(item)
- count= count +1
- meal_total=int(meal_total)+int(item)
- output = str(count)
- print(meal)
- print("You have spent " + str(meal_total) + " on your meal.")
- cash= int(input("How much cash have you given?"))
- leftover = int(cash)-int(meal_total)
- print(("You should receive $" +str(leftover)+" in your change!"))
- elif command == "bye":
- finished = True
- else:
- print ("sorry I can't do that yet!!!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement