0

It won't print do not leave username blank as it is invalid input when I press enter(blank input)

def strchecker(question):
    valid=False
    while not valid:
        user_Name = input(question)
        if user_Name!="":
            valid=True
            return user_name
        else:
            print("Do no leave username blank")

print("*************Welcome to the Te Reo Maori Quiz***************")
user_Name = str(input("Please enter your username")) 
2
  • 1
    What version of Python are you using? If you are using Python 2, you should use raw_input instead of input Commented Jun 28, 2018 at 21:52
  • 3
    You are never running your function strchecker Commented Jun 28, 2018 at 21:55

1 Answer 1

1

You haven't actually called the function; that's probably why it's not working. Try this:

def strchecker(question):
    while True:
        user_Name = input(question)
        if user_Name:
            return user_Name  # Make sure to capitalize the N in user_Name
            break
        else:
            print("Do no leave username blank")

print("*************Welcome to the Te Reo Maori Quiz***************")
user_Name = strchecker("Please enter your username") 

This should work.

Sign up to request clarification or add additional context in comments.

2 Comments

One redundancy I would remove in your post (and the OP's) is re-assigning the user_Name variable within strchecker. You don't need to do that
@Jade make sure you're careful about naming your variables! :). user_Name is different than user_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.