#flag in while loop issue

59 messages · Page 1 of 1 (latest)

true orbit
spiral kiln
#

whats the actual problem?

true orbit
#

everything works except the else

spiral kiln
#

you are comparing

#

flag == False

#

i assume u want to asign

#

instead

true orbit
#

is the == in the while the issue

spiral kiln
#

yeah i guess

true orbit
#

ill see

spiral kiln
#

the rest looks fine to me 👍
although i dont code in python that often anyore

true orbit
#

i want it to loop back to beginning

#

this is my issue

#

changed the == still doing it

spiral kiln
#

i think maybe you should use a function instead

true orbit
#

how so

#

i just thought using a flag was the easiest way to loop it]

spiral kiln
#

nvm yeah ur right

#

can i see your edited code please?

true orbit
#

here it is

#

wait

#

yeah that right

#

changed the == on the flag

#

cannot do that for the beginning

#

should i use for instead>?

spiral kiln
#

honestly im pretty confused what ur tryna do

#

ur code is also poorly indented, but thats a seperate issue

true orbit
#

i am making a hangman game. i wanted this introdction to loop

#

as a start to the game

true orbit
spiral kiln
#

ohhhh right

#

what do you type for the input?

true orbit
#

yes or no

#

if its not either i want it to print error message and loop to beginning

#

everything else works

whole yarrow
#

Just as a tip, random.randint() takes two parameters, start and stop, which are both integers

true orbit
whole yarrow
#

randint() is used to return an integer between the start and stop parameters, if you want it to select a word, you'd use choice() with a list

true orbit
#

ah thank you

whole yarrow
#

And, to make things easier, could you use codeblocks and copypaste the code instead of screenshots?

#

!formatting

vagrant crystalBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```py
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB

true orbit
#

""py
beginning = input("welcome to hangman! would you like to play? ")

flag = True

while flag == True:

if beginning == ("no"):
exit()
elif beginning == ("yes"):
flag = False
else:
flag = True
print ("incorrect answer. please use yes or no")
""

#

thanks for being patient with me im not the smarted coder so far

whole yarrow
#

I tried running that code with an online compiler, and it works perfectly

true orbit
#

hahah

#

what the hell

whole yarrow
true orbit
#

oh i think we have the wrong idea

#

this is just for the beginning of the code in the menu

#

to either start or not start the game

whole yarrow
#

So you want it to keep asking for the input to be either yes or no?

true orbit
#

thats why i said i think im getting a bit ahead of myself. i just wanted to warm myself back up to it

whole yarrow
#

Move the input into the while loop

true orbit
#

fixed

#

what a simple fix