Hello,
I have an exercise where the user can choose among three options, giving name, printing name, and ending the programme.
Due to the menu structure, the user can choose to print the name before the name is inputted by option 1. This leads to “NameError: name (sometexthere) is not defined”.
while (True):
print("This programme in capable of realising the following fuctions:", "\n", "1) Give name", "\n", "2) Print name", "\n", "0) End", sep="")
valinta = input("Give your choice: ")
if choice == "1":
nimi = input("Give name: ")
elif choice == "2":
print("Name is '", "", str(name), "", "'.", sep="")
if name == NameError:
print("The name is not yet given.")
elif choice == "0":
print("Thank you for using this programme.")
break
else:
print("Something went wrong.")
I tried to do this in the following ways:
except ValueError:
if (emptyValueCondition):
if nameError:
if name == nameError:
except ValueError:
seems to be about ensuring the user does not input data in wrong form.
Nothing seems to yet work. Thank you in advance.