10 Data Validation

Minimum Length

1
2
3
4
5
6
7
print("Usernames must be 4 or more characters long")
username =input("Type in your username")

if len(username) <4:
    print("username not long enough")
else:
    print("usename authenticated")

Empty String

1
2
3
4
5
6
username =input("Type in your username")

if username=="":
    print("empty")
else:
    print("not empty")

Validation on Range

E.g. checking that a username is between 5 and 8 characters long

1
2
3
4
5
6
username =input("Type in your username")

if len(username) <5 or len(username) >8:
    print("username must b between 5 and 8 characters long")
else:
    print("Authenticated")

Username/ Password Authentication

1
2
3
4
5
6
7
8
]
username=input("What is your username?")
password=input("What is your password?")

if username=="admin" and password=="Hello12":
    print("Authenticated")
else:
    print("Not authenticated")

Quiz

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
print("Usernames must be 4 or more characters long")
username =input("Type in your username")

if len(username) <4:
    print("username not long enough")
else:
    print("usename authenticated")

username =input("Type in your username")

if username=="":
    print("empty")
else:
    print("not empty")

username =input("Type in your username")

if len(username) <5 or len(username) >8:
    print("username must b between 5 and 8 characters long")
else:
    print("Authenticated")

username=input("What is your username?")
password=input("What is your password?")

if username=="admin" and password=="Hello12":
    print("Authenticated")
else:
    print("Not authenticated")