-1

I'm trying to understand how to return to the top of a Python script from an else statement.

print('lets do some math!')
math_operation = input('Which would you like to start with, addition, subtraction or division?  ')
if math_operation == "addition":
    input_add1 = int(input('First number please '))
    input_add2 = int(input('Second number please '))
    result = input_add1 + input_add2
    print(f'{input_add1} + {input_add2} = {result}')
elif math_operation == "subtraction":
    input_sub1 = int(input('First number please '))
    input_sub2 = int(input('Second number please '))
    result = input_sub1 - input_sub2
    print(f'{input_sub1} - {input_sub2} = {result}')
else:
    print('I did not quite get that, lets try again')
    

input_div = int(input('now provide a number that is divisible from the answer'))

answer = result / input_div

print(answer)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

You need to put this inside a loop,

math_operation= None
print('lets do some math!')
while math_operation != 'quit':
    math_operation = input('Which would you like to start with, addition, subtraction or division? or quit')
    ... your code ...
Rahul K P
  • 15,740
  • 4
  • 35
  • 52