Takže mám jednoduchý kalkulačka v Pythonu. Takže to, co to dělá, je, žádá o operace (jako sčítání) a se zeptá na první číslo a druhé číslo.
Řekněme, že si vyberu toho,
první číslo: 1
druhé číslo: 1
výsledek: 2
A poté, co že to chci se zeptat: typ {x} začít nový výpočet
Když jste typ x je to v podstatě restartuje všechno, takže si můžete dělat různé výpočty. ( {x} může to být cokoliv, mě to nevadí)
Jak to mám udělat, že?
současný kód:
print("Which operation do you want to do?")
print("Type + for addition")
print("Type - for subtraction")
print("Type * for multiplication")
print("Type / for division")
op = input('Enter your choice here = ')
if op == '+' :
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number here: "))
add = num1 + num2
print("{0} + {1} is {2}".format(num1, num2, add))
elif op == '-' :
num1 = float(input("Enter the first number here: "))
num2 = float(input("Enter the second number here: "))
sub = num1 - num2
print("{0} - {1} is {2}".format(num1, num2, sub))
elif op == '*' :
num1 = float(input("Enter the first number here: "))
num2 = float(input("Enter the second number here: "))
multi = num1 * num2
print("{0} * {1} is {2}".format(num1, num2, multi))
elif op == '/' :
num1 = float(input("Enter the first number here: "))
num2 = float(input("Enter the second number here: "))
division = num1 / num2
print("{0} / {1} is {2}".format(num1, num2, division))
else :
print("something went wrong!")