Python Forum
Syntax "for" loop, "and", ".isupper()", ".islower", ".isnum()"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax "for" loop, "and", ".isupper()", ".islower", ".isnum()"
#5
Note that this code:

if password.isupper():
    print("Password is not valid")
else:
    if password.islower(): 
        print("Password is not valid")
    else:     
        if password.isnumeric(): 
            print("Password is not valid")
        else:
            if  len(intersection(characters, special_characters))==0:
                print("Password is not valid")
            else:
                if len(password)<6 or len(password)>12:
                    print("Password is not valid")
                else:
                    print('Valid password')
Is equivalent to this code:

if password.isupper():
    print("Password is not valid")
elif password.islower(): 
    print("Password is not valid")
elif password.isnumeric(): 
    print("Password is not valid")
elif len(intersection(characters, special_characters))==0:
    print("Password is not valid")
elif len(password)<6 or len(password)>12:
    print("Password is not valid")
else:
    print('Valid password')
That is, 'elif' in python is equivalent to 'else if' in many other languages. That's not going to fix the problems ThomasL pointed out, but it's definitely something you should use moving forward.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Syntax "for" loop, "and", ".isupper()", ".islower", ".isnum()" - by ichabod801 - Sep-06-2019, 01:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax Error: Invalid Syntax in a while loop sydney 1 4,120 Oct-19-2019, 01:40 AM
Last Post: jefsummers
  SyntaxError: Invalid syntax in a while loop ludegrae 3 14,813 Dec-18-2018, 04:12 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020