2
# Imports
import re

# Variables
contestants = []


def run(string):
    incorrectSymbols = re.compile('[@_!#$%^&*()<>?/\|}{~:]')
    if (incorrectSymbols.search(string) == None):
        return "yes"
    else:
        return "no"


def bootUp():
    print(""">>> Hello judges!
>>> Today you will be viewing 6 contestants!
>>> To continue please enter all contestants names!""")
    contestantNames()


def contestantNames():
    for i in range(0, 6):
        while True:
            x = input(">>> Contestant number " + str(i) + " name: ")
            if run(x) == "yes":
                break
            elif run(x) == "no":
                print(">>> No symbols allowed!")
            elif x=="":            # Here is what im confused about.
                print(">>> You can't leave it blank!")
            else:
                print(">>> Error in run function.")
    contestants.append(x)
    print(contestants)


bootUp()

After reading up on this problem I found multiple accounts saying to do this simply use (variable)="" . However, this does not work for me, any other ideas?

My code is an attempt for a dance project where contestants all take turns and each judge scores each contestant. A tournament to be put simply. This part of the code would be the beginning where I obtain the contestant's names and i need to make sure they have no symbols or left blank.

1 Answer 1

4
  • Somehow it looks like your run is not working as you expected. Its returning 'yes' and 'no' not True and False. Ordering of your if else is wrong you need to fix that.
  • just move up if x=='' condition and it will work.
# Imports
import re

# Variables
contestants = []


def run(string):
    incorrectSymbols = re.compile('[@_!#$%^&*()<>?/\|}{~:]')
    if (incorrectSymbols.search(string) == None):
        return "yes"
    else:
        return "no"


def bootUp():
    print(""">>> Hello judges!
>>> Today you will be viewing 6 contestants!
>>> To continue please enter all contestants names!""")
    contestantNames()


def contestantNames():
    for i in range(0, 6):
        while True:
            x = input(">>> Contestant number " + str(i) + " name: ")
            if x == "":            # Here is what im confused about.
                print(">>> You can't leave it blank!")
            elif run(x) == "yes":
                break
            elif run(x) == "no":
                print(">>> No symbols allowed!")
            else:
                print(">>> Error in run function.")
    contestants.append(x)
    print(contestants)


bootUp()
  • Another solution is to change run function like this.
def run(string):
    if string == "":
        return
    incorrectSymbols = re.compile('[@_!#$%^&*()<>?/\|}{~:]')
    if (incorrectSymbols.search(string) == None):
        return "yes"
    else:
        return "no"

This will work with your default if else ordering.

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

1 Comment

rookie mistake x)

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.