I have a script which has multiple raw_input statements. I would like to add the ability to enter 'undo' and allow the user to go back and re-enter the last raw_input value. How can I accomplish this without a goto type statement?
import sys
prompt_a = raw_input('Please enter x for x \nPlease enter y for y \nPlease enter c to cancel: ') or 'x'
prompt_a = prompt_a.lower()
if prompt_a == 'c':
sys.exit()
prompt_b = raw_input('Please enter x for x \nPlease enter y for y \nPlease enter c to cancel \nPlease enter u to go back to previous question: ') or 'x'
if prompt_b == 'c':
sys.exit()
#I would like to GOTO prompt a if the user entered u in the last prompt
prompt_c = raw_input('Please enter x for x \nPlease enter y for y \nPlease enter c to cancel \nPlease enter u to go back to previous question: ') or 'x'
if prompt_c == 'c':
sys.exit()
#I would like to GOTO prompt b if the user entered u in the last prompt
Update
def function1(user_input):
var_a = user_input.lower()
def function2(user_input):
var_b = user_input.lower()
def function3(user_input):
var_c = user_input.lower()
processing_functions = [function1, function2, function3]
progress = 0
while progress < len(processing_functions):
user_input = raw_input("Enter input please: ")
if user_input == "UNDO":
progress -= 1
print("Returning to previous input.")
else:
print("Processing " + user_input)
progress += 1
if progress == 1:
function1(user_input)
elif progress == 2:
function2(user_input)
elif progress == 3:
function3(user_input)
print("Processing complete.")
print(var_a)
print(var_b)
print(var_c)