#flag in while loop issue
59 messages · Page 1 of 1 (latest)
whats the actual problem?
everything works except the else
is the == in the while the issue
yeah i guess
ill see
the rest looks fine to me 👍
although i dont code in python that often anyore
i want it to loop back to beginning
this is my issue
changed the == still doing it
i think maybe you should use a function instead
here it is
wait
yeah that right
changed the == on the flag
cannot do that for the beginning
should i use for instead>?
honestly im pretty confused what ur tryna do
ur code is also poorly indented, but thats a seperate issue
this does not work ofcourse
yes or no
if its not either i want it to print error message and loop to beginning
everything else works
Just as a tip, random.randint() takes two parameters, start and stop, which are both integers
thanks:) gonna do my research on that later after this is fixed i know where to go when i struggle haha
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
ah thank you
And, to make things easier, could you use codeblocks and copypaste the code instead of screenshots?
!formatting
""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
I tried running that code with an online compiler, and it works perfectly
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
So you want it to keep asking for the input to be either yes or no?
thats why i said i think im getting a bit ahead of myself. i just wanted to warm myself back up to it
Move the input into the while loop