Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Dungeon Game Dungeon Entrance

What is the purpose of ("> ") in the while loop?

Confused on the purpose of this string.

3 Answers

I know this is waay late, but I believe you are referring to the following code:

while True:
    print("Welcome to the dungeon!")
    print("You're currently in room {}") # fill with player position
    print("You can move {}") # fill with available moves
    print("Enter QUIT to quit.")

    move = input("> ")
    move = move.upper()

    if move == 'QUIT':
        break

It helps to include the code but I'm pretty sure this is what concerned you, as I found it peculiar as well. The way the input() function works is, when written as input("insert text here"), the quoted text is printed as a prompt to get the desired input.

So, in the case of input("> "), the user will see:

and they are expected to plug in the desired input after that, followed by a return. This will record the input to the 'move' variable.

I hope that helps someone, at least.

Hmmm... it seems "> " is coded to be a quote... that makes it a little tricky to show, here. Pretty much, though, the user will see the greater-than symbol and will be prompted to type after that. Whatever they type after that is recorded into the variable 'move' as soon as they hit the 'Enter' key.

">" means greater than. so in a while loop is it usually used to evaluate a counter to keep you in the loop

ie.

Z = 10
while Z > 1:  #reads as while Z is greater than 1
    print(Z)
    Z = Z-1  #can also be written as Z -= 1

As long as Z greater than 1 it will print the value of Z

hope that helps!

-Shawn

its basic dude