I can set the variable and print it directly after if choice == 1. But if choice == 2 i cant print it out the text that was set, I get an error.
(UnboundLocalError: local variable 'text_in_use' referenced before assignment)
How can i fix this?
text_in_use = ''
encrypt_key = ''
def menu():
choice = int(input("""1: Input text to work with
2: Print the current text
3: Encrypt the current text
4: Decrypt the current text
5: Exit
Enter Choice: """))
if choice == 1:
text_in_use = str(input("Enter Text: ")).upper()
print("Text to use was set to:", text_in_use)
menu()
elif choice == 2:
print(text_in_use) #this is where i get the error <-----
menu()
elif choice == 3:
print("3")
menu()
elif choice == 4:
#decrypt()
print("4")
menu()
elif choice == 5:
#exit()
print("5")
menu()
menu()
i just want it to print the text that was set.
text_in_use = str(input("Enter Text: ")).upper()
before theif
statement begins. – lmiguelvargasfmenu()
again after each input, and the next execution ofmenu()
doesn't remember the text that was entered in the previous execution. It's probably best to rearrange your code so that all the logic happens within the same execution. – John Gordon