I just started to learn python by myself, and i made a basic calculator.
However, i want to let the script go to the start if the user press a button that there's no option on the script, for example:
'1 Addition'
'2 Substract'
'3 Multiply'
'4 Divide'
The option 5 does not exist, so i want to make that when the user press '5' the scripts prints 'Error' and then the script returns to the start, printing the options i writed above. For example, like in a batch file, when you want to go at the start of the script after do something, you use:
goto start
start:
(options)
This is my code:
print ('Choose something')
print ('1 Addition')
print ('2 Substract')
print ('3 Multiply')
print ('4 Divide')
option = input('Choose option');
number = int(input('First number '));
numbertwo = int(input('Second number'));
def addition (z, v) :
return z + v;
def substract (f, h,) :
return f - h;
def multiply (u, i,) :
return u * i;
def divide (n, k) :
return n / k;
if option == '1':
print(numbertwo, "+" ,numbertwo, "=", addition(numero, numerodos));
elif option == '2':
print(number, "-" ,numbertwo, "=", substract(number, numbertwo));
elif option == '3':
print(number, "*" ,numbertwo, "=", multiply(number, numbertwo));
elif option == '4':
print(number, "/" ,numbertwo, "=", divide(number, numbertwo));
elif option == '5':
print("Error")
I tried to do it, but i just get the printed message and then the script ask for the numbers.
Any idea of how can i do it?