Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- finished = False
- # Asks the user what its name is and stores it as a value
- # Asks user for their name and stores it under user_name
- user_name = input("What is your name?>")
- bots_name = "Mansoor" # Name of the bot
- print("Hi, I'm " + bots_name + ", your personal bot.")
- print("Welcome " + user_name + "!!")
- while not finished:
- # This shows the user the options available for the bot to perform
- print("What would you like to do?")
- print("1 - Add 2 numbers")
- print("2 - Subtract 2 numbers")
- print("3 - Calculate the area of a triangle")
- print("4 - Caculate the area of a square")
- print("5 - Multiply 2 numbers")
- print("6 - Divide 2 numbers")
- print("7 - Calculate the average of a set of numbers")
- print("8 - Generate a shopping list")
- print("9 - Calculate Area of a circle")
- print("10 - Find the roots of a quadratic function")
- print("11 - End program")
- value = input("Value> ")
- print(" ")
- # If the person picks 1, then they trigger the addition command
- if value == "1" or value == "one" or value == "One":
- print("Let's add some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 + number2
- addoutput = str(result)
- print(input1 + " + " + input2 + " = " + addoutput)
- print(" ")
- # If the person picks 2, then they trigger the subtraction command
- elif value == "2":
- print("Let's subtract some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 - number2
- suboutput = str(result)
- print(input1 + " - " + input2 + " = " + suboutput)
- print(" ")
- # If the person picks 3, then they calculate the area of a triangle
- elif value == "3" or value == "three" or value == "Three":
- print("Let's calculate the area of a triangle") # (b*h)/2
- base = input("Base (in cm)> ")
- height = input("Height (in cm)> ")
- numbase = int(base)
- numheight = int(height)
- result = numbase * numheight/2
- trioutput = str(result)
- print("Area of the triangle = " + trioutput + "cm\u00b2")
- print(" ")
- # If the person picks 4, then they can calculate a square number
- elif value == "4" or value == "four" or value == "Four":
- print("Let's calculate area of a square") # n^2
- length = input("length (in cm)>")
- numx = int(length)
- result = numx * numx
- sqoutput = str(result)
- print("Area of this square is = " + sqoutput + "cm\u00b2")
- print(" ")
- # If the person picks 5, then they multiply two numbers
- elif value == "5" or value == "five" or value == "Five":
- print("Let's multiply some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 * number2
- multoutput = str(result)
- print(input1 + " x " + input2 + " = " + multoutput)
- print(" ")
- # If the person picks 6, then they divide numbers
- elif value == "6" or value == "six" or value == "Six":
- print("Let's divide some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- if input2 == "0":
- print("Invalid solution")
- print(" ")
- else:
- result = number1 / number2
- divoutput = str(result)
- print(input1 + " / " + input2 + " = " + divoutput)
- print(" ")
- # If the person picks 7, this means they are able
- # to calculate averages of a set of numbers
- elif value == "7" or value == "seven" or value == "Seven":
- 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) + "> ")
- total = total + int(number)
- result = total/how_many
- print("The average = " + str(result))
- print(" ")
- # If the person picks 8, it will let you generate a shopping list
- elif value == "8" or value == "eight" or value == "Eight":
- shopping = []
- shopping_cost = []
- count = 0
- shopping_total = 0
- how_many = input("How many items of shopping do you need?> ")
- how_many = int(how_many)
- for item_number in range(how_many):
- item = input("What is item number " + str(item_number + 1) + " ?> ")
- shopping.append(item)
- count = count + 1
- price = input("How much does item number " + str(item_number + 1) + " cost?> £")
- fltprice = float(price)
- shopping_cost.append(price)
- shopping_total += fltprice
- print("Shopping list:")
- for item in shopping:
- print(item)
- strcount = str(count)
- if count == 1:
- print("There is only 1 thing you need to get")
- else:
- print("There are " + strcount + " things you need to get")
- strshopping_total = str(shopping_total)
- print("Shopping total = £" + strshopping_total)
- print(" ")
- # If the person picks 9 it calculates the area of a circle using 3.142
- elif value == "9" or value == "nine" or value == "Nine":
- print("Let's calculate the area of a circle")
- rd = input("What is the radius of the circle? (in cm)> ")
- radius = int(rd)
- CircArea = math.pi * radius * radius
- StrCirc = str(CircArea)
- print("The area of this circle is " + StrCirc + "cm\u00b2" )
- print(" ")
- elif value == "10" or value == "ten" or value == "Ten":
- print("Let's find the roots of a quadratric"
- a = input("What is your coefficient of x\u00b2?> ")
- b = input("What is your coefficient of x?> ")
- c = input("What is the integer value?> ")
- inta = int(a)
- intb = int(b)
- intc = int(c)
- Discriminant = (intb*intb)-4*inta*intc
- if Discriminant > 0:
- print("There are 2 real solutions")
- print("And they are: ")
- PosRoot = ( (-intb) + math.sqrt(Discriminant) ) / ( 2 * inta )
- NegRoot = ( (-intb) - math.sqrt(Discriminant) ) / ( 2 * inta )
- strPosRoot = str(PosRoot)
- strNegRoot = str(NegRoot)
- print("Root 1> " + strPosRoot)
- print("Root 2> " + strNegRoot)
- print(" ")
- elif Discriminant == 0:
- print("There is only 1 real solution")
- print("And they are: ")
- SingRoot = ( (-intb) + math.sqrt(Discriminant) ) / ( 2 * inta )
- strSingRoot = str(SingRoot)
- print("Root - " + strSingRoot)
- print(" ")
- else:
- print("There are no real solutions")
- print(" ")
- # If the person picks 11 the program ends
- elif value == "11" or value == "eleven" or value == "Eleven":
- finished = True
- print("Bye " + user_name)
- print(" ")
- # What the person entered was invalid
- else:
- print("I'm sorry, but that isn't a valid value")
- print("Please pick a number between 1 and 10")
- print(" ")
- # If the person picks 4, then they can calculate a square number
- elif value == "4" or value == "four" or value == "Four":
- print("Let's calculate area of a square") # n^2
- length = input("length>")
- numx = int(length)
- result = numx * numx
- sqoutput = str(result)
- print("Area of this square is = " + sqoutput)
- # If the person picks 5, then they multiply two numbers
- elif value == "5" or value == "five" or value == "Five":
- print("Let's multiply some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- result = number1 * number2
- multoutput = str(result)
- print(input1 + " x " + input2 + " = " + multoutput)
- # If the person picks 6, then they divide numbers
- elif value == "6" or value == "six" or value == "Six":
- print("Let's divide some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- if input2 == "0":
- print("Invalid solution")
- else:
- result = number1 / number2
- divoutput = str(result)
- print(input1 + " / " + input2 + " = " + divoutput)
- # If the person picks 7, this means they are able
- # to calculate averages of a set of numbers
- elif value == "7" or value == "seven" or value == "Seven":
- 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) + "> ")
- total = total + int(number)
- result = total/how_many
- print("The average = " + str(result))
- # If the person picks 8, it will let you generate a shopping list
- elif value == "8" or value == "eight" or value == "Eight":
- shopping = []
- shopping_cost = []
- count = 0
- shopping_total = 0
- how_many = input("How many items of shopping do you need?> ")
- how_many = int(how_many)
- for item_number in range(how_many):
- item = input("What is item number " + str(item_number + 1) + " ?> ")
- shopping.append(item)
- count = count + 1
- price = input("How much does item number " + str(item_number + 1) + " cost?> £")
- fltprice = float(price)
- shopping_cost.append(price)
- shopping_total += fltprice
- print("Shopping list:")
- for item in shopping:
- print(item)
- strcount = str(count)
- if count == 1:
- print("There is only 1 thing you need to get")
- else:
- print("There are " + strcount + " things you need to get")
- strshopping_total = str(shopping_total)
- print("Shopping total = £" + strshopping_total)
- elif value == "9" or value == "nine" or value == "Nine":
- finished = True
- print("Bye " + user_name)
- # What the person entered was invalid
- else:
- print("I'm sorry, but that isn't a valid value")
- print("Please pick a number between 1 and 9")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement