Previous Index Next

Solved Examples

Question 1

Write a program that checks entered password is valid or not. For a password to be valid it must be at least eight characters long and have at least one special character.

Program

password = input('Enter a password: ')

if len(password) < 8:
    print('Use 8 characters or more for password.')
elif password.isalnum():
    print('At least one special character required')
else:
    print('Password is valid')

Output

Sample Run # 1
Enter a password: india
Use 8 characters or more for password.

Sample Run # 2
Enter a password: goldenfish12
At least one special character required

Sample Run # 3
Enter a password: gold@2021
Password is valid

Question 2

Write a program that accepts a string. Your program should delete all numbers from it.
Example if entered string is 'Welcome to 2021 class.' it should display 'Welcome to class'

Program

text = input('Enter a string: ')

for letter in text:
    if not letter.isdigit():
        print(letter, end='')

Output

Enter a string: Welcome to 2021 class
Welcome to  class

Previous Index Next