The problem states as follows:
Example output:
Calculator
Give the first number: 100
Give the second number: 25
(1) +
(2) -
(3) *
(4) /
(5)Change numbers
(6)Quit
Current numbers: 100 25
Please select something (1-6): 5
Give the first number: 10
Give the second number: 30
(1) +
(2) -
(3) *
(4) /
(5)Change numbers
(6)Quit
Current numbers: 10 30
Please select something (1-6): 1
The result is: 40
(1) +
(2) -
(3) *
(4) /
(5)Change numbers
(6)Quit
Current numbers: 10 30
Please select something (1-6): 6
Thank you!
And my solution was:
print("Calculator")
var1 = input("Give the first number: ")
var2 = input("Give the second number: ")
print("(1) +\n(2) -\n(3) *\n(4) /\n(5)Change numbers\n(6)Quit")
print("Current numbers: " + var1 + " " + var2)
opcion = input("Please select something (1-6): ")
while (opcion != "6"):
if (opcion == "1"):
var3 = int(var1) + int(var2)
print("The result is: " + str(var3))
elif (opcion == "2"):
var3 = int(var1) - int(var2)
print("The result is: " + str(var3))
elif (opcion == "3"):
var3 = int(var1) * int(var2)
print("The result is: " + str(var3))
elif (opcion == "4"):
var3 = int(var1) / int(var2)
print("The result is: " + str(var3))
elif (opcion == "5"):
var1 = input("Give the first number: ")
var2 = input("Give the second number: ")
opcion = input("Please select something (1-6): ")
else:
print("Selection was not correct.")
print("Thank you!")
But in "elif (opcion == "5"):" the automatic corrector states that I fell in an infinite loop, I tried a break after the two new numbers are entered, but it completely exits from the while-loop, any ideas? Thank you.