Habibullah Ahmadi
Habibullah Ahmadi

Reputation: 1

How do I check if user input has entered nothing?

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.

Upvotes: 0

Views: 1364

Answers (1)

Swagrim
Swagrim

Reputation: 422

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)

Upvotes: 2

Related Questions