#๐Ÿ”’ Help

54 messages ยท Page 1 of 1 (latest)

arctic nestBOT
#

@solar hawk

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.

blazing kayak
#

@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?

solar hawk
#

yes

winged yew
solar hawk
#

what should i do then

#

im new idk much about it

blazing kayak
#

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

solar hawk
#
      #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?

sour wagon
#

an else statement

blazing kayak
#

Correct

solar hawk
#

      #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
sour wagon
#

because it does not update the input

solar hawk
#

how do i do it?

sour wagon
#

and its the end of the loop either way so it reruns the loop

#

whats the point of the loop

solar hawk
#

so it confirms if u wanna name ur friend what u chose

blazing kayak
#

Anything other than a yes should be retry scenario right?

solar hawk
#

anything other than yes/no

#

i mean

#

yes

sour wagon
#

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

blazing kayak
solar hawk
#

oh i see

sour wagon
#

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
blazing kayak
sour wagon
#

tested it and it does not

blazing kayak
#

Ah you have a variable there

#

You could just do while ongoing

#

No need to compare it with true

sour wagon
#

๐Ÿคท๐Ÿปโ€โ™‚๏ธ

blazing kayak
#

You also learning python atm?

sour wagon
#

that actually does not work

blazing kayak
#

This is like an anti pattern

blazing kayak
sour wagon
#

nevermind

#

forgot i took out the bool change cause i accidentally had == and thought it worked before fixing it for a second

blazing kayak
#

while (some thruthy or falsely) that's the syntax

sour wagon
#

only takes out 1 word no biggie

blazing kayak
#

Don't mean to be pedantic or anything, you'll learn to avoid these eventually ๐Ÿ˜

sour wagon
#

your splitting hairs

blazing kayak
#

@solar hawk you can close this thread, if the problem is solved

solar hawk
#

ok

arctic nestBOT
#
Python help channel closed

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