Ask Question
13 September, 22:42

7.6 LAB: Checker for integer string 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

+4
Answers (1)
  1. 13 September, 23:42
    0
    Following are the program in the Python Programming Language:

    def check (num) : #define function

    if (num. isdigit ()) : #set if statement

    return "yes"; #return yes if condition is true

    else:

    return "no"; # return no if condition is false

    string=input ("Enter the numbers 0-9: ") #get input from the user

    print (check (string)) #print and call the function

    Output:

    Enter the numbers 0-9: 1995

    yes

    Enter the numbers 0-9: 42,000

    no

    Explanation:

    Here, we define a function "check () " and pass an argument in its parameter "num" inside the function.

    we set if-else conditional statement and check the value stored in the variable "num" is the digit by using built in function "isdigit () " then return "yes". Then, otherwise it return "no".

    Finally, we get the input from the user in the variable "string" then, we call the function through "print () " function.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “7.6 LAB: Checker for integer string Forms often allow a user to enter an integer. Write a program that takes in a string representing an ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers