Ask 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 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

+3
Answers (1)
  1. 28 August, 10:58
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers