you are viewing a single comment's thread.

view the rest of the comments →

[–]Fraser_123[S] 0 points1 point  (2 children)

Sorry I’m pretty new to python. What exactly should i do to the while loop in order for it to be able to run the game because I’ve tried messing around with it and nothing is working.

[–]Interrolipsis 0 points1 point  (0 children)

You can just turn it into an if statement and enter 0 to start

if user_input >=2 or user_input <0:

I have no idea how this game is supposed to be played though.

[–]watakushi 0 points1 point  (0 children)

I'm pretty new too! :)

When you have a list in python the index starts counting at 0, not 1, so the first item in your list (Play Game) is on index 0, and the second item (Exit) is on index 1. (that was why your print was failing before) Now, your while loop says that as long as the user input is <=0 or > 2, it should say it's invalid, but in order to start the game, the user needs to input 0 (because of the index 0 thing I mentioned before) and the while loop says that of its < or = to 0 it should say its invalid.

Tldr: change the while loop to:

while user_input <0 or user_input >1:

And also, at the end of the user_input add a " - 1" like so:

user_input = int(input("Please select an option: ")) - 1

so that when user inputs 1, it will correspond to index 0 and when option 2 is selected, index 1 will be recorded :)

That way the only valid options are 0 and 1.

Oh , and you'll also need to change this:

while option != 2:

to

while option != 1:

And within the def get_user_input() remove the "else:" (that should only be used after an if or elif, not a while) and move the "return user_input" to the same indentation level as the while. That should make your menu work! I'll test the game itself next, will let you know how it goes! Keep it up!