148k views
2 votes
IN PYTHON****

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.
Ex: If the input is:
1995
the output is:
yes
Ex: If the input is:
42,000
or any string with a non-integer character, the output is:
no

1 Answer

0 votes

Answer:

num_str = input("Enter an integer: ")

if num_str.isdigit():

print("Yes")

else:

print("No")

Step-by-step explanation:

In this software, the input() function is used to request the user to provide a string representing an integer. The input string is then called with the isdigit() method to determine whether each character is a digit. The application outputs "Yes" if the isdigit() method returns True. Otherwise, "No" is displayed by the application.

You can test it in Python or any open editor online and enter a variable such as 20 where it will output yes and enter say AZ or -650 and it will output no.

User Matt Saunders
by
8.0k points