Sarah
Sarah

Reputation: 9

String Checker, Invalid Input - Python

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")) 

Upvotes: 0

Views: 59

Answers (1)

Hypnotron
Hypnotron

Reputation: 96

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.

Upvotes: 1

Related Questions