Check if a string has a number or not

In this program, we will take a string as input and check if a string has a number or not.

Steps to solve the program
  1. Take a string as input.
  2. Create a count variable and assign its value equal to 0.
  3. Use for loop to iterate over each character of the string.
  4. If the character is a number add 1 to the count variable.
  5. Use isnumeric() to check for numbers.
  6. If in the end count is greater is 0 then the string has a number.
  7. Print the output. 
				
					#Input string
string = "python1"
count = 0

for char in string:
    if char.isnumeric():
        count += 1
        
#Checking for numbers
if count > 0:
    print("Given string have a number")
else:
    print("Given string does not have a number")
				
			

Output :

				
					Given string have a number
				
			

print characters at even places in a string.

count the number of vowels in a string.

Leave a Comment