25.4k views
4 votes
Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9.

User Jczaplew
by
3.5k points

2 Answers

4 votes

Answer:

text = input("enter a value: ")

if text.isdigit():

print("yes")

Step-by-step explanation:

The program is written in python.

text = input("enter a value: ") This expression prompt the user to input a string value containing any form of character . The inputted character might be letters, digits etc.

if text.isdigit():

This check if the inputted value is a digit .

print("yes")

if the value is a digit the system will display yes.

User Aaron Broad
by
3.4k points
4 votes

Answer:

user_string = input("Input a string : ")

output = user_string.isnumeric()

if output == True:

print("yes")

else:

print("no")

Step-by-step explanation:

  • First of all check whether user input have all numeric value or not .
  • Display yes if string contain all numeric values .
  • Display no if string contain at least one non - integer character .

User Fannik
by
3.2k points