#๐ Help
54 messages ยท Page 1 of 1 (latest)
@solar hawk
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.
@solar hawk you have two while loops one inside the other
Your script is supposed to take the name of a friend and confirm it's yes or no then exit or retry?
yes
True!
And it only breaks out of the while True the break is in.
That's alright
You should remove the second while loop and correct the indent
After that, if yes then break, if no then continue
Break will break the loop, continue will skip the current iteration
Retrying it basically
Continue is not even required but it's just implying the meaning
#Choosing friend's name
print("\nNow you will choose a name for your friend.")
while True:
friend= input("\nEnter your friend's name \n --> ")
print(f"\nYour friend's name is {friend}. Correct?")
#Confirmation
friendyes= input("\nYes \nNo \n \n --> ")
if friendyes.lower() == 'yes':
print("\nFriend successfully created.")
break
elif friendyes.lower() == 'no':
print("\n Choose again.")
#Done```
Fixed it :) Tyy
Btw I want it to ask the user to choose the correct option if they choose anything other than yes/no. what should I add?
an else statement
Correct
#Choosing friend's name
print("\nNow you will choose a name for your friend.")
while True:
friend= input("\nEnter your friend's name \n --> ")
print(f"\nYour friend's name is {friend}. Correct?")
#Confirmation
friendyes= input("\nYes \nNo \n \n --> ")
if friendyes.lower() == 'yes':
print("\nFriend successfully created.")
break
elif friendyes.lower() == 'no':
print("\n Choose again.")
else:
print("\n Choose Yes/No")
#Done```
After I choose anything other than yes/no it tells me to choose friends name again
because it does not update the input
how do i do it?
and its the end of the loop either way so it reruns the loop
whats the point of the loop
so it confirms if u wanna name ur friend what u chose
Anything other than a yes should be retry scenario right?
if you want yes to break the loop and no or anything else to retry the loop that is what that code does
if you want no to ask for a new friend name and anything else to make them choose yes or no again then youd have to make another loop
so you loop through the yes/no stage until you get an answer
If it's no or something else other than yes, it'll ask for the friend again
oh i see
something like this would work if you are trying to get them to keep going until they type yes or no
ongoing = True
print("\nNow you will choose a name for your friend.")
while ongoing == True:
friend = input("\nEnter your friend's name \n --> ")
print(f"\nYour friend's name is {friend}. Correct?")
# Confirmation
while True:
friendyes = input("\nYes \nNo \n \n --> ")
if friendyes.lower() == 'yes':
print("\nFriend successfully created.")
ongoing = False
break
elif friendyes.lower() == 'no':
print("\n Choose again.")
break
else:
print("\n Choose Yes/No")
# Done
This would ask for the friend again, if you see ops initial question
tested it and it does not
Ah you have a variable there
You could just do while ongoing
No need to compare it with true
๐คท๐ปโโ๏ธ
You also learning python atm?
that actually does not work
This is like an anti pattern
Why it doesn't?
nevermind
forgot i took out the bool change cause i accidentally had == and thought it worked before fixing it for a second
while (some thruthy or falsely) that's the syntax
only takes out 1 word no biggie
Don't mean to be pedantic or anything, you'll learn to avoid these eventually ๐
your splitting hairs
@solar hawk you can close this thread, if the problem is solved
ok
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.
๐ Help