Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #FutureLearn Python 101 - Silly the Math Bot
- print("Hi, I am Silly, your personal math bot")
- print("I am here to assist. Now lets get started!")
- users_name = input("Please enter your name")
- print("Welcome, " + users_name + ".")
- #do_calculation_plus_times() function for add, mult
- def do_calculation_plus_times():
- print("Lets " + command + " some numbers...")
- how_many = input("How many numbers will you " + command + ">")
- how_many = int(how_many)
- total_add = 0
- total_multiply = 1
- for num_count in range(how_many):
- number = input("Enter number " + str(num_count + 1) + ">")
- if command == "add" or command == "+":
- total_add = total_add + float(number)
- output = str(total_add)
- elif command == "multiply" or command == "*" or command == "x":
- total_multiply = total_multiply * float(number)
- if command == "add" or command == "+":
- output = str(total_add)
- elif command == "multiply" or command == "*" or command == "x":
- output = str(total_multiply)
- print("Your total = " + output)
- #do_calculation_sub_div() function for subtract/divide
- def do_calculation_sub_div():
- print("Lets " + command + " two numbers")
- input1 = input("Number 1>")
- input2 = input("Number 2>")
- number1 = float(input1)
- number2 = float(input2)
- if command == "subtract" or command == "-":
- operator = " - "
- result = (number1 - number2)
- elif command == "divide" or command == "/" or command == "div":
- operator = " / "
- result = (number1 / number2)
- output = str(result)
- print(input1 + operator + input2 + " = " + output)
- #do_calculation_total_avg() function for totals and averages
- def do_calculation_total_avg():
- print("Lets " + command + " some numbers...")
- how_many = input("How many numbers will you " + command + ">")
- how_many = int(how_many)
- total = 0
- list_numbers = []
- for num_count in range(how_many):
- number = input("Enter number " + str(num_count + 1) + ">")
- list_numbers.append(number)
- total = total + int(number)
- if command == "average" or command == "avg" or command == "%":
- result = int(total / how_many)
- elif command == "total":
- result = int(total)
- print("Your numbers: " + str(list_numbers))
- print("Your " + command + " = " + str(result))
- #start program
- quit = False
- while quit == False:
- command = input("How can I help? (bye or q to quit)")
- #Addition with looping
- if command == "add" or command == "+":
- do_calculation_plus_times()
- #Subtraction
- elif command == "subtract" or command == "-":
- do_calculation_sub_div()
- #Multiplication with looping
- elif command == "multiply" or command == "*" or command == "x":
- do_calculation_plus_times()
- #Division
- elif command == "divide" or command == "/" or command == "div":
- do_calculation_sub_div()
- #Triangle Area Calculation
- elif command == "area":
- print("Lets calculate a triangle's area...")
- input1 = input("Triangle base>")
- input2 = input("Triangel height>")
- number1 = int(input1)
- number2 = int(input2)
- result = (number1 * number2)/2
- output = str(result)
- print("Triangle with base: " + input1 + " and height: " + input2 + " has an area of " + output)
- #Calculating Averages and Totals with looping
- elif command == "average" or command == "avg" or command == "%" or command == "total":
- do_calculation_total_avg()
- #Shopping List and Total Calculator with lists and loops
- elif command == "shopping" or command == "list" or command == "shopping list":
- shopping = []
- prices = []
- total = 0
- count = 0
- how_many = input("How many shopping items today? ")
- how_many = int(how_many)
- for item_num in range(how_many):
- item = input("Enter item nubmer " + str(item_num + 1) + ">")
- shopping.append(item)
- price = float(input("Enter its cost>"))
- prices.append(price)
- total += price
- count = count + 1
- total_items = str(count)
- count = 0
- for item_num in shopping:
- print(str(count+1) + ". " + shopping[count])
- count = count + 1
- print("You have " + total_items + " items in your shopping list")
- print("Those " + total_items + " items total cost is $" + str(total))
- #Cost of Meal Divider
- elif command == "meal divider" or command == "meal div":
- input1 = input("What is the total cost of the bill>")
- input2 = input("How many people are splitting the bill>")
- number1 = float(input1)
- number2 = int(input2)
- result = (number1 / number2)
- output = str(result)
- print("Total cost per person = " + output)
- elif command == "bye" or command == "q":
- quit = True
- else:
- print("Sorry " + users_name + ", I don't understand " + "'" + command + "'")
- print("Thank you, goodbye!")
- #end program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement