I am somewhat new to python and have a very basic understanding.
I am creating a very simple program that works as a decision map. The user types 0 for no, and 1 for yes, in order to continue down the decision map and ultimately reach a conclusion. For each decision, the answer (0 or 1) is saved in a new variable.
MY PROBLEM: I created a function to validate that the user is entering a valid response. I want to use this function after every-time I ask for a new response for each new decision/ variable. For example, in the first variable, seq, if the user enters 2, it should enter the validation function and enter a loop until the user enters 0 or 1. However, once they enter 0 or 1, I don't know how to re-assign that new value to seq in order to continue with the decision map.
What I have tried: Setting x to global, initiate x = 0
, set the variable (i.e seq) to global, and add seq = valid_user_input(x)
Any help would be greatly appreciated. I am looking for a simple solution that is hopefully not too advanced for me. HERE IS A LINK TO EDIT MY CODE! Repl.it map program
#Validation Function
def valid_user_input(x):
while x != 1 and x != 0:
x = int(input("Please answer the following question with [0 being no] and [1 being yes]\n"))
print("x value is: ", x)
return x
#Conditions/ Call Validation Function
seq = int(input("Is your equation in the {An} form or a list of terms?\n0. No]\n[1. Yes]\n"))
valid_user_input(seq) #CALL FUNCTION
if seq == 0: #seq no
print("You have a series!\n")
part = int(input("Is your equation in the form Sn?\n[1. Yes]\n[0. No]\n"))
valid_user_input(part) #CALL FUNCTION
if part == 0: #part no
#Continue conditions...
if part == 1: #part yes
if seq == 1: #seq yes
print("You have a sequence!")
tels = int(input("Do all terms cancel out except first and last term?\n[1. Yes]\n[0. No]\n"))
valid_user_input(tels) #CALL FUNCTION