#πŸ”’ I'm having trouble with making a while loop for my code

38 messages Β· Page 1 of 1 (latest)

drowsy sapphire
#

I was making Tic-Tac-Toe and I want to ask the player if they want to play again after the game is over. If they say yes, the game will start again. if they say no, the game says Have a nice day and the game stops.
But I'm having trouble with the while-loop.
If I were to do this:

continue = True
While continue:

(game codes)

continue = input("Would you like to play again? (yes/no)")
if continue == "yes":
continue = True
elif continue == "no":
continue = False
print("Goodbye!")

The game just keeps going on, if i remove the continue = True, the code gets an error. The error is "name 'continue' is not defined"

Could someone help me please?

delicate raftBOT
#

@drowsy sapphire

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

rustic pewter
drowsy sapphire
ornate phoenix
#

!paste

delicate raftBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

rustic pewter
#

So the code is not written in python? Or you mean the text and comments are not in English?

drowsy sapphire
#

some of the text and comments yes

#

Can I just copy paste the code here?

delicate raftBOT
#

Hey @drowsy sapphire!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
drowsy sapphire
#

oh thanks! wait, i didnt see it

warm siren
#

You can use paste bin

#

!paste

delicate raftBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

drowsy sapphire
#

thank you!

#

sorry that It's taking a bit long for me. I'm having a bit of trouble

warm siren
#

What trouble?

drowsy sapphire
#

do i now click on repaste?

#

or download?

warm siren
# delicate raft

Click on the link here > paste your code (paste button on bottom left) > then share thr link of that page

delicate raftBOT
#

Please react with βœ… to upload your file(s) to our paste bin, which is more accessible for some users.

drowsy sapphire
#

ohh

#

ohhh

#

thank you πŸ˜„

warm siren
#

So you are facing the problem of while loop closing even after thr player says yes to plau again?

steel anchor
#

your doorgan is always True, you do the input outside the while loop

rustic pewter
#

The last 6 or so lines are outside the while loop

drowsy sapphire
drowsy sapphire
warm siren
steel anchor
rustic pewter
#

Indent the last 6 or so lines. Currently they will only run if the while loop exits

drowsy sapphire
#

OHHHHHH!! Thank you all so much!!

#

🀩

delicate raftBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.