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

Shawn Denham
PRO
Shawn Denham
Pro Student 16,787 Points

">" 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

Jebadeiah Jones
Jebadeiah Jones
6,329 Points

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.

Jebadeiah Jones
Jebadeiah Jones
6,329 Points

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.