I am new to python, and I am likely over complicating this. I am having problem with values in variables within a function not being replaced. Instead, it seems to just be adding the new value to it. With this function, if you select 1 or 2, it is supposed to perform certain actions, if you select anything else, it is supposed to say that is not an option and have you try again. Here is the output if I select a wrong option before selecting a valid option:
Select Option
[1] Option 1
[2] Option 2
You selected Option 1
1
9
7
6
So instead of replacing the value of my variable to 1 and clearing previous values, it seems to just add to it. Here is my code:
def testfunc():
testvar = input('Select Option\n\n[1] Option 1\n[2] Option 2\n\n >')
if testvar in ('1', 'Option 1', 'option 1'):
print("\nYou selected Option 1")
elif testvar in ('2', 'Option 2', 'option 2'):
print("\nYou Selected Option 2")
else:
print("\n\nThat is not an option, please select another option")
testfunc()
print(testvar)
testfunc()
If I could have someone explain why its storing multiple values and how I can prevent this, I would really appreciate it. Thanks!
testvar = input()line.