Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- keep_running = True
- count = 0
- def do_calculation():
- # function to remove duplicated lines of code from add and subtract conditions
- print("Lets " + command + " some numbers.")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = float(input1)
- number2 = float(input2)
- if command == "add" or command == "Add":
- operator = "+"
- result = number1 + number2
- elif command == "subtract" or command == "Subtract":
- operator = "-"
- result = number1 - number2
- # print the result to the screen
- output = str(result)
- print(input1 + " operator " + input2 + " = " + output)
- print ("Hi, I am Marvin, your personal bot.")
- print()
- users_name = input("Please enter your name : ") #ask for users name
- while keep_running == True:
- # print ("Hi, I am Marvin, your personal bot.")
- # print()
- # users_name = input("Please enter your name : ") #ask for users name
- print ("Hi " + users_name + ". I hope you enjoy using the bot.")
- print ("This bot will allow you to do simple mathematical procedures.")
- #command = input("So " + users_name + ", Would you like to 1 Add, 2 Subtract, 3 Divide, 4 Multiply, 5 find the Average of some numbers, or 6 create a Shopping List : ")
- command = input("So " + users_name + ", Would you like to Add, Subtract, Divide, Multiply, find the Average of some numbers, \n create a Shopping List or enter to end : ")
- # all numbers are floating point just in case decimals are needed
- if command == "add" or command == "Add" or command == "plus" or command == "Plus" :
- #add 2 numbers together
- do_calculation()
- elif command == "subtract" or command == "Subtract" or command == "minus" or command == "Minus":
- #subtract 2 numbers from each other
- do_calculation()
- #print("Lets subtract some numbers from each other.")
- #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 == "multiply" or command == "Multiply":
- #multiply 2 numbers by each other
- print("Lets multiply some numbers together.")
- 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 == "Divide":
- #divide 2 numbers with each other
- print("Lets " + command + " some 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 == "average" or command == "Average":
- #find the average of several numbers
- print("Lets find the " + command + " of some numbers.")
- print(command + " has just been implemented. So here we go.")
- # Numcount = input("how many number would you like to average? > ")
- how_many = input("How many numbers? } ")
- how_many = int(how_many)
- Avelist = []
- total = 0
- for number_count in range (how_many):
- Avenumber = input("Enter number " + str(number_count) + " } ")
- total = total + float(Avenumber)
- Avelist.append(Avenumber)
- result =total / how_many
- result = result
- for Avenumber in Avelist:
- print(Avenumber)
- print("The average of the numbers above = " + str(result))
- elif command == "Shopping List" or command == "shopping list" or command == "Shopping list" or command == "shopping List":
- # shopping list creator
- shopping = [] #holds the shoopping items
- itemprice = [] # contains the item cost
- total_sum = 0 #variable for the total cost of the shopping items
- keep_shopping = True
- num = 0 #vriable for total number if items
- total_sum = 0
- while keep_shopping == True:
- #set up using a while statement to collect items until bye entered by user
- item = input("enter the item name or bye to finish : ")
- # ends the loop
- if item == "bye" or item == "Bye":
- keep_shopping = False
- continue
- shopping.append(item)
- price = input("enter the item price : ")
- itemprice.append(price)
- total_sum = total_sum + float((price))
- num = num +1
- print("Total shopping cost so far : " + str(total_sum) + " for : " + str(num) + " items")
- # prints the shopping list and total cost
- print ("Shopping list\n")
- for item_number in range(num):
- print (shopping[item_number] + "\t\t\t" + itemprice[item_number] )
- print ("------------------------------------")
- print ("Total cost \t\t$" + str(total_sum)+ " for : " + str(num) + " items")
- else: #just in case they did not choose one of the options
- print("Sorry " + users_name + " but the bot can only Add, Subtract, Divide, Multiply, find the Average of numbers or creater a Shopping list")
- print("Cheers " + users_name)
- print()
- print("Hey " + users_name + ", thanks for using the Mathematics and Shopping list creator bot. Cheers Marvin.")
- if command == "":
- keep_running = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement