162k views
3 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. 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

User Clanket
by
4.1k points

1 Answer

4 votes

Answer:

Following are the program to the given question:

def check_digit(number): #defining a method check_digit that takes number variable in parameter

if(numumber.isdigit()): #use if to check value is digit

return "yes"; #use return to return string value "yes"

else: #else block

return "no";#use return to return string value "no"

string=input("Enter the numbers 0-9: ") #defining a variable string that input value from the user

print(check_digit(string)) #use print that call the method and print its return value

Output:

Please find the attached file.

Step-by-step explanation:

In this code a method "check_digit()", which accepts an argument "number" in its parameter inside the function.

A conditional statement is used if it checks the number used "isdigit()" method that checks value is a digit and return value "yes" and in the else block it will return value "no".

Outside the method, a variable "string" is declared that input the value from the user-end and call the check_digit and print its value.

Forms often allow a user to enter an integer. Write a program that takes in a string-example-1
Forms often allow a user to enter an integer. Write a program that takes in a string-example-2
User Slavus
by
4.0k points