Password
Check
Q.Given a word, check if it is a valid password or
not. A password is said to be valid if it satisfies the following
conditions:
i) Should begin with a letter
ii) Should contain atleast one digit and one special
character
iii) Length of the password should be atleast 8
Print ‘Valid' if the given word satisfies the above
three conditions and print ‘Invalid’ otherwise.
Input format:
A word
Output format:
Print ‘Valid' if the given word satisfies the above
three conditions and print ‘Invalid’ otherwise.
Input:
The
password(password)
Processing
length
= len(password)
count_digit
= 0
count_special
= 0
for
i in range(length):
if i == 0:
if password[0].isalpha() == False:
break
else:
if password[i].isdigit() == True:
count_digit+=1
continue
elif password[i].isalpha() == False:
count_special+=1
continue
Output:
Display
if the password is Valid or Invalid.
Algorithm:
Step1.
Get the password(password)
Step2.
Initialize count_digit and count_special as zero
Step3.
Let length variable be assigned as the length of the password.
Step4.
Check if length is less than 8 if yes then diplay Invalid else proceed to step5
Step5.
initialize i as 0 and repeat till i is less than length.
Step5.1
if i is equal to zero then check if ith character of the password variable is
not an alphabet if true then break out of the loop.
Step5.2
if i is not equal to zero then proceed to step5.3
Step5.3
check if ith character of password is a digits list if true then increment
count_digit variable by 1 and increment i by one and then move on to the loops
starting point else move on to step 5.4
Step5.4
check if ith character of password is an alphabet if false then increment
count_special variable by 1 and increment i by one and then move on to the
start of the loop.
Step6.
Check if both count_digit and count_special are not equal to zero if true
display Valid else display Invalid.
Step7.End
Program:
password
= input()
length
= len(password)
count_digit
= 0
count_special
= 0
if
length >= 8:
for i in range(length):
if i == 0:
if password[0].isalpha() == False:
break
else:
if password[i].isdigit() == True:
count_digit+=1
continue
elif password[i].isalpha() ==
False:
count_special+=1
continue
if count_digit == 0 or count_special == 0:
if count_digit == 0 or count_special == 0:
print('Invalid')
else:
print('Valid')
Flowchart:
To edit this flowchart click on this
No comments:
Post a Comment