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 == "+":
- result = number1 + number2
- operator = " + "
- elif command == "-":
- result = number1 - number2
- operator = " - "
- output = str(result)
- print(input1 + operator + input2 + " = " + output)
- def do_sum_average():
- total=0
- # Requests how many numbers are to be entered and average found
- how_many=input("how many numbers do you wish to "+ command + "? > ")
- how_many=int(how_many)
- # Requests numbers to be averaged
- for number_count in range(how_many):
- number_count=number_count+1
- number = input("Enter number " + str(number_count) + "> ")
- total = total + int(number)
- if command=="average":
- result = total / how_many
- else:
- result=total
- print("the " +command+" = " + str(result))
- #This statement introduces the Bot by name
- print("Hi, I am Marvin, your personal Bot.")
- #
- finished=False
- # Seeks input and allocates to variable "command"
- while finished==False:
- command=("")
- while command!="+" and command!="-" and command!="*" and command!="/" and command!="average" and command!="Temperature Conversion" and command !="Total" and command!="bye":
- #
- command=input("Select Function: +, -, *,/,average, Total, Temperature Conversion,bye ")
- #
- #Tests if Bot is to Add
- if command=="+":
- do_calculation()
- #
- #Tests if Bot is to subtract
- elif command=="-":
- do_calculation()
- #
- #Tests if Bot is to multiply
- elif command=="*":
- #Requests numbers
- print("enter your numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- #converts to integer variables
- number1 = int(input1)
- number2 = int(input2)
- #completes calculation, converts result to string and prints
- result = number1 * number2
- output=str(result)
- print(input1 + " x " + input2 + " = " + output)
- #
- #Tests if Bot is to divide
- elif command=="/":
- #Requests numbers
- print("enter your numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- #converts to integer variables
- number1 = int(input1)
- number2 = int(input2)
- #completes calculation, converts result to string and prints
- result = number1 / number2
- output=str(result)
- print(input1 + " / " + input2 + " = " + output)
- # Tests if bot is to average
- elif command=="average":
- do_sum_average()
- elif command=="Total":
- do_sum_average()
- #
- # Tests if selection is Temperature Conversion
- elif command=="Temperature Conversion":
- temp_choice="0"
- while temp_choice !="1" and temp_choice!="2":
- temp_choice=input("Please select 1=Celsius to Fahrenheit 2=Fahrenheit to Celsius > ")
- if temp_choice=="1":
- tempc=input("Input Temp in Celsius> ")
- tempc_int=float(tempc)
- tempf_int=(tempc_int*9/5)+32
- tempf=str(tempf_int)
- print(tempc+" degrees Celsius = "+tempf+" degrees Fahrenheit")
- else:
- tempf=input("Input Temp in Fahrenheit> ")
- tempf_int=float(tempf)
- tempc_int=(tempf_int-32)*5/9
- tempc=str(tempc_int)
- print(tempf+" degrees Fahrenheit = "+tempc+" degrees Celsius ")
- elif command=="bye":
- finished=True
- else:
- print("Do not understand")
- print("Goodbye come back soon")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement