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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 <target_var>.isdigit() function (e.g., "2".isdigit() will return True) or string comparison such as "0" <= target <= "9"

  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 function inside 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 and Output

#### Example 1

**Input:**

```
s
a
w
l
1
```

**Output:**

```
Your digit is 1
```

---

#### Example 2

**Input:**

```
6
```

**Output:**

```
Your digit is 6
```

---

#### Example 3

**Input:**

```
d
g
!
w
g
d
e
4
```

**Output:**

```
Your digit is 4
```
Transcribed Image Text:### Example Input and Output #### Example 1 **Input:** ``` s a w l 1 ``` **Output:** ``` Your digit is 1 ``` --- #### Example 2 **Input:** ``` 6 ``` **Output:** ``` Your digit is 6 ``` --- #### Example 3 **Input:** ``` d g ! w g d e 4 ``` **Output:** ``` Your digit is 4 ```
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education