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
Write a Python program to demonstrate the use of the join function.
Explain any four string operators.
Write a Python program for the following task:
Take a string entered by the user and check if it begins with the letter "a" or not. If it begins with "a", the user is prompted that it is the first name on the list. If it does not begin with "a", the user is prompted that the string does not begin with the letter "a".
Write a Python program to check that a given string is a palindrome or not.