How can I check if the user has entered nothing and let's say if it were true, how do I replace the empty string with the letter "Z"?
simple example:
if middlename == "":
middlename = middlename.replace("", "Z")
else:
print(middlename)
Nothing is being shown on the console.
CodePudding user response:
at the last of the if statement, you forgot to print the middlename. That's why it's not printing anything. Another thing, you don't need to use replace method, instead you can simply use middlename = "Z". And the last one, there's no need to use else statement. just type the if statement and its functions and then break out of the if statement and then print the middlename.
Full code:
if middlename == "":
middlename = "Z"
print(middlename)