213k views
3 votes
Write a program that takes in a string representing an integer as input, and outputs 'yes' if every character is a digit 0-9 or 'no' otherwise.

User Mpontus
by
7.4k points

1 Answer

4 votes

Final answer:

To check if every character in a string is a digit, you can use the isdigit() function in most programming languages.

Step-by-step explanation:

To write a program that checks if every character in a string is a digit, you can use the isdigit() function in most programming languages. Here's an example in Python:

def check_digits(string):
for char in string:
if not char.isdigit():
return 'no'
return 'yes'

input_string = input('Enter a string: ')
result = check_digits(input_string)
print(result)

In this program, we define a function check_digits() that iterates over each character in the string. If any character is not a digit, it immediately returns 'no'. Otherwise, it returns 'yes' at the end. You can test the program with different input strings to see the output.

User Frank Andrew
by
8.3k points

No related questions found