Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

How can I improve my logic

I finished the practice differently from the video, but it works lol. Just wanted someone to overview my code to give pointers on what i could improve on.

team = []

add_members= input("Would You Like To Add Players To The Team? (Yes/No): ").upper()

def Add_Teammates():
    going = True
    while going:
        team.append(input("Enter Player Name: ").upper())
        print(team)
        adding = input("Add Another? ").upper()
        if adding == "YES":
            continue
        else:
            going = False


if add_members == "YES":
    Add_Teammates()
else:
    print(team)

print(f"The current roster size is {len(team)} and the members are: ")
team_num = 0
for member in team:
    team_num += 1
    print(f"{member.upper()} {team_num}")

goalkeeper = int(input("Select a Goaly from the team by entering the player's number: "))
print(f"You Selected {team[goalkeeper-1]} as the team GoalKeeper")

1 Answer

Steven Parker
Steven Parker
231,007 Points

You can eliminate the variables from the function:

def Add_Teammates():
    while True:
        team.append(input("Enter Player Name: ").upper())
        print(team)
        if input("Add Another? ").upper() != "YES":
            break