Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def do_calculation(): # function that replace some code in add and subtract operations
- 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)
- finished = False
- while finished == False:
- print()
- print("Hi, I am Atom, your personal bot.")
- print("You can select one word of the menu, writing the word:")
- print("add subtract multiply divide volume average shopping bye")
- command = input("How can I help you? ")
- # This if works when the word of the menu is wrong, giving a message "Sorry, I don't understand."
- if command !="add" and command !="subtract" and command !="multiply" and command !="divide" and command !="volume" and command !="average" and command !="shopping" and command != "bye":
- print("Sorry, I don't understand.")
- elif command == "add" or command == "plus": # Adding code with function do_calculation() in line 30
- do_calculation()
- elif command == "subtract": # Adding code with function do_calculation() in line 36
- do_calculation()
- elif command == "multiply" or command == "multiplication": # Adding code to multiply in lines 38-46
- print("lets multiply two numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = float(input1)
- number2 = float(input2)
- result = number1 * number2
- output = str(result)
- print(input1 + " * " + input2 + " = " + output)
- elif command == "divide" or command == "division": # Adding code to divide in lines 48-56
- print("lets divide two numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = float(input1)
- number2 = float(input2)
- result = number1 / number2
- output = str(result)
- print(input1 + " / " + input2 + " = " + output)
- elif command == "Volume" or command == "volume": # Adding code to volume in lines 58-67
- print("lets calculate volume of cylinder with 2 values, ratio and high in cms.")
- input1 = input("ratio > ")
- input2 = input("high > ")
- ratio = float(input1)
- high = float(input2)
- #pi1 = 3.14
- result = math.pi * ratio * ratio * high
- output = str(result)
- print("volume of cylinder = " + output + " cms^3")
- elif command == "average" or command == "Average": # Adding code to average in lines 69-78
- print("lets calculate the average of some numbers!")
- 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 = " + str(result))
- elif command == "shopping" or command == "Shopping": # Adding code to shopping in lines 80-94
- shopping = []
- how_many = input("how many items of shopping do you have? ")
- how_many = int(how_many)
- total = 0
- for item_number in range (how_many):
- item = input("What is the value of item " + str(item_number + 1) + "? ")
- shopping.append(item)
- total = total + float(item)
- print(shopping)
- print("Total shopping = " + str(total))
- for item in shopping:
- print(item)
- print("You have " + str(len(shopping)) + " items in your shopping list" + " and the total shopping is = " + str(total))
- else:
- if command == "bye" or command == "Bye":
- finished = True
- print("session finished")
- print("Bye")
Advertisement
Add Comment
Please, Sign In to add comment