#πŸ”’ Return to old while function

22 messages Β· Page 1 of 1 (latest)

slate leaf
#

Hey I am pretty new to programming in general I have a small question. As a little practice I wanted to do a simple program that checks if some conditions are met for a username and a password. The problem that I am facing is, after one if statement is complete, it never returns to check if that statement is still true for the new username or password. It simply just checks for the new condition. Is there a way to keep checking all my conditions that I set? Thanks in advance πŸ˜„

outer raftBOT
#

@slate leaf

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.

slate leaf
#


#Headline
print("Hello User, please enter your Username and password down below")

#User Inputs
user = input("Enter your username: ")

while user == "":
    print("You did not fil out your username!")
    user = input("Enter your username: ")

password = input("Enter your password: ")

while password == "":
    print("You did not enter a password!")
    password = input("Enter your password: ")

#Criteria Checks
while len(user) < 4 or len(user) > 10:
    if len(user) < 4 or len(user) > 10:
      print("Your username needs to be between 4 and 10 letters long")
      user = input("Enter your username: ")

while not user.isalpha():
    if not user.isalpha():
        print("Your username can not contain any numbers")
        user = input("Enter your username: ")

print(user)```
outer raftBOT
#

Hey @slate leaf!

It looks like you incorrectly specified a language for your code block.

Make sure you put your code on a new line following py. There must not be any spaces after py.

Here is an example of how it should look:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
zealous rock
#

you have to put them inside the same loop

slate leaf
#

the same while loop?

zealous rock
#

yes

minor crypt
#

you need to create another while loop to handle that logic

slate leaf
#

are the other conditions then stated in an elif??

minor crypt
#

you should create one while loop just to verify the username

#

if you have multiple conditions you want to check at once, it's better to use a while True loop

#

and then break the loop when all your conditions are met

slate leaf
#

how can i implement a '''while True''' with this

minor crypt
#
while True:
    username = input("Enter your username")
    if len(username) < 8:
        print("Username too short")
    elif not username.isalpha():
        print("Letters only")
    else:
        break
#

it would look something like this

#

you can expand on it as needed with whatever conditions you require

slate leaf
#

Thanks a lot that really helped me

trim jungle
#

if you use indicators, like username_accepted, pw_accepted.. you could allow for starting over without needing to restart the script

slate leaf
#

Thanks guys u really helped me

#

!close

outer raftBOT
#
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.