KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Write a Python program to check that a given string contains only alpha numeric characters. If user is not entering alphanumeric characters prompt him or her to enter it again.

Python String Manipulation

3 Likes

Answer

string1 = input("Enter a string: ")
while True:
    if string1.isalnum():
        print("The given string contains only alphanumeric characters")
        break
    else:
        print("Please enter only alphanumeric characters")
        string1 = input("Enter the string again: ")

Output

Enter a string: Python@123
Please enter only alphanumeric characters
Enter the string again: Python123
The given string contains only alphanumeric characters

Answered By

1 Like


Related Questions