Working with users in python

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
Working with users in python
A keyboard can be really tricky, if it's broken! 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_single_digit (text) that checks if the string parameter text is a digit. The function should return the
Boolean True or False
2. In your main program, get the input from the user (use input())
3. Repeatedly read the input, until the user inputs a digit. (use while)
4. When they finally provide a digit as an input, then output it as follows: Your digit is DDD (where DDD is replaced by the provided
digit).
Note that the program execution stops as soon as the user provides a single digit.
Example input
S
a
W
1
1.1. The string contains only one digit if the string length is 1 and the character inside is a digit character.
1.2. To check if the character is a digit character use <target_var>.isdigit() function (e.g., "2". isdigit() will return True);
alternatively you can use string comparison such as "0" <= target <= "9".
Example Output
Your digit is 1
Example input
6
Example Output
Your digit is 6
Transcribed Image Text:A keyboard can be really tricky, if it's broken! 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_single_digit (text) that checks if the string parameter text is a digit. The function should return the Boolean True or False 2. In your main program, get the input from the user (use input()) 3. Repeatedly read the input, until the user inputs a digit. (use while) 4. When they finally provide a digit as an input, then output it as follows: Your digit is DDD (where DDD is replaced by the provided digit). Note that the program execution stops as soon as the user provides a single digit. Example input S a W 1 1.1. The string contains only one digit if the string length is 1 and the character inside is a digit character. 1.2. To check if the character is a digit character use <target_var>.isdigit() function (e.g., "2". isdigit() will return True); alternatively you can use string comparison such as "0" <= target <= "9". Example Output Your digit is 1 Example input 6 Example Output Your digit is 6
CS 3000
!
W
g
d
e
4
Example Output
Your digit is 4
Hints!
• When we cannot predict how many times we will need to repeat an action, that is when we use a while statement.
• Call your function inside the while statement or save your function result each time and use that result in a while statement.
Only when the execution gets out of the while loop (i.e., the loop-continuation-condition is False), you know that the program can
print the Your digit is
●
422020.2684366.qx3zqy7
LAB
ACTIVITY
4.20.1: LAB: Working with users
1 def is_single_digit(text):
2
3
4
5
6
###
The function expects
param: var_name (var_type)
The result is ...
||||||
7
8
9 if __name_
pass
_main__':
main.py
0/12
Load default template...
Transcribed Image Text:CS 3000 ! W g d e 4 Example Output Your digit is 4 Hints! • When we cannot predict how many times we will need to repeat an action, that is when we use a while statement. • Call your function inside the while statement or save your function result each time and use that result in a while statement. Only when the execution gets out of the while loop (i.e., the loop-continuation-condition is False), you know that the program can print the Your digit is ● 422020.2684366.qx3zqy7 LAB ACTIVITY 4.20.1: LAB: Working with users 1 def is_single_digit(text): 2 3 4 5 6 ### The function expects param: var_name (var_type) The result is ... |||||| 7 8 9 if __name_ pass _main__': main.py 0/12 Load default template...
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
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.
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