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 Python Basics All Together Now Branch and Loop

Steven Zhang
Steven Zhang
310 Points

repeating the code until a certain input

Before you read the question, please look at where I am in the python language course.

I want to repeat my code over and over before the user inputs a certain word. I was thinking of While loops or functions. Is there any way I can repeat the code with just while loops, and how?

1 Answer

Steven Parker
Steven Parker
231,269 Points

Repeating code is exactly what loops are good for. A simple example that meets your description might be:

word = None
while word != "certain":
    word = input("What is the special word? ")
print("Yep, that was it!")