Python!! Learning Objectives Use the while loop to repeat action an unknown number of times Practice input() statement inside the loop Learn complex string comparison condition inside the...


Python!!


Learning Objectives



  • Use the while loop to repeat action an unknown number of times

  • Practice input() statement inside the loop

  • Learn complex string comparison condition inside the the while loop

  • Create a function with a given name and parameter and given return values

  • Use if/else statements inside the function to achieve different return statements by condition

  • Use int() integer conversion function to have the number from string


Instructions


A keyboard can be really tricky! You try to enter a number but it prints a letter again and again! Let's try to fix that.




  1. Create a function is_this_digit(input_line) that checks if the string parameter is a digit. The function should return True or False


    1.1. String contains only one digit if the string length is 1 and the character inside is digit character. To check last condition use .isdigit() function (e.g., "2".isdigit() will return True) or string comparison such as "0" <= target=""><=>




  2. Read the input from the user(use input())




  3. Continue to repeat reading the input, until user inputs digit




  4. When we finally have a digit provided as an input, then output it in the following sentence: Your digit is DDD (where DDD is replaced by the provided digit).







Hints!



  • When we cannot predict how many times will we need to repeat the action - that is when we use the while statement.

  • Call your functioninside the while statement or save your function result each time and use that result in while statement.


The code I should complete:


def is_this_digit(input_line):
    # Define your function here
    pass


if __name__ == '__main__':
    # Type your code here.




Example input<br>S<br>a<br>W<br>1<br>Example Output<br>Your digit is 1<br>Example input<br>Example Output<br>Your digit is 6<br>Example input<br>!<br>W<br>d<br>4<br>Example Output<br>Your digit is 4<br>

Extracted text: Example input S a W 1 Example Output Your digit is 1 Example input Example Output Your digit is 6 Example input ! W d 4 Example Output Your digit is 4
Jun 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here