PY
py
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
#Password length must be 7 characters
#Password must have 2 numbers at least
#password must have 2 special characters from ("@"$"!"*"%"#"&")
#Note: when password is wrong the code runs normally,but I get EOf in line 5! I don't know why?
#However,once the password match the requirments,the code runs correctly without any errors! and I have run this in python playground I got no errors.
#Define the valied special characters
special_characters="$!@#&*%"
while True:
#Get the user's input
password=input("Enter the password: ")
#intialize the conditions
length_valid=len(password) >=7
digit_count=sum(char. isdigit() for char in password)
digit_valid=digit_count >=2
special_count= sum(char in special_characters for char in password)
special_valid=special_count >=2
#Check if all conditions are met
if length_valid and digit_valid and special_valid:
print("Access granted")
break
else:
print(" Please try again")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run