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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Dominick Chism](https://uploads.teamtreehouse.com/production/profile-photos/11558155/micro_2DE48785-BB82-486F-9511-2D415102D5A3.jpg)
Dominick Chism
8,857 PointsIs this good code practice?
I tried to complete the invalid attempts section of this video by using just loops, but I'm unsure if it's good practice or not. I did take an Python course in college and if I remember correctly I could've swore I stumbled across a problem on StackOverflow that said sys.exit() was bad practice. Any help would be appreciated!
password = input("Please enter the super secret password: ")
MASTER_PASSWORD = 'opensesame'
i = 1
while i <= 3:
while password != MASTER_PASSWORD:
password = input("Invalid password, try again: ")
i += 1
break
if password == 'opensesame':
print("Welcome")
else:
print("Too many invalid password attempts\nTotal invalid attempts: {}".format(i))
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsThe video code segment is intended to prevent execution of some later code (not shown in the video sample) unless the correct password is entered. The use of system.exit() provided a convenient way to control program flow. Remember that the point of the lesson is just to demonstrate loop functionality.
And yes, it's more elegant to control program flow otherwise, and what you have here would do the job providing that the entire rest of the program was placed between the "welcome" message and the following "else".