3. Complete the function count_digits. This function takes one parameter - a string (s). It should return the number of digits in s. For example, if s is "25 or 6 to 4 is a song by Chicago" then count_digits should return 4. count_digits should not print the result- it should return it. Do not change anything outside count_digits. Save & Run Load History Show CodeLens 1 def count_digits(s): '''Returns the number of digits in s''' 2 pass #Hint: make a string of digits to use #in checking whether each character #is a digit. And use the accumulator #pattern 4 7 9 user_string = input("Please enter a string: ") 10 num_digits 11 print("There are", num_digits, "digits in", user_string) count_digits(user_string) %3D 12

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
### Task 3: Implement the `count_digits` Function

**Objective:**
Complete the function `count_digits`. This function takes one parameter - a string (`s`). It should return the number of digits in `s`. 

**Example:**
If `s` is "25 or 6 to 4 is a song by Chicago", then `count_digits` should return `4`.

**Instructions:**
- The function `count_digits` should not print the result; it should return it.
- Do not change anything outside the `count_digits` function.

**Code Implementation:**

```python
def count_digits(s):
    '''Returns the number of digits in s'''
    pass
    # Hint: make a string of digits to use
    # in checking whether each character
    # is a digit. And use the accumulator
    # pattern

user_string = input("Please enter a string: ")
num_digits = count_digits(user_string)
print("There are", num_digits, "digits in", user_string)
```

- **Line 1-2:** Define the function `count_digits` with parameter `s` and include a docstring.
- **Line 3:** Use `pass` as a placeholder for future implementation.
- **Lines 4-7:** Comments provide hints to implement the digit counting logic using a string of digits and an accumulator pattern.

**User Interaction:**
- **Line 9:** Prompt the user to enter a string.
- **Line 10:** Call the `count_digits` function with the user input and store the result in `num_digits`.
- **Line 11:** Print the number of digits found in the inputted string alongside the original string.
Transcribed Image Text:### Task 3: Implement the `count_digits` Function **Objective:** Complete the function `count_digits`. This function takes one parameter - a string (`s`). It should return the number of digits in `s`. **Example:** If `s` is "25 or 6 to 4 is a song by Chicago", then `count_digits` should return `4`. **Instructions:** - The function `count_digits` should not print the result; it should return it. - Do not change anything outside the `count_digits` function. **Code Implementation:** ```python def count_digits(s): '''Returns the number of digits in s''' pass # Hint: make a string of digits to use # in checking whether each character # is a digit. And use the accumulator # pattern user_string = input("Please enter a string: ") num_digits = count_digits(user_string) print("There are", num_digits, "digits in", user_string) ``` - **Line 1-2:** Define the function `count_digits` with parameter `s` and include a docstring. - **Line 3:** Use `pass` as a placeholder for future implementation. - **Lines 4-7:** Comments provide hints to implement the digit counting logic using a string of digits and an accumulator pattern. **User Interaction:** - **Line 9:** Prompt the user to enter a string. - **Line 10:** Call the `count_digits` function with the user input and store the result in `num_digits`. - **Line 11:** Print the number of digits found in the inputted string alongside the original string.
### Objective
Complete the function `show_upper`. This function takes one parameter - a string (`s`). It should return a string made up of all the upper-case characters in `s`. For example, if `s` is `"aBdDEfgHijK"`, then `show_upper` should return `"BDEHK"`. It should return the upper-case string - not print it. Do not change anything outside `show_upper`.

### Code

```python
def show_upper(s):
    '''Returns the upper case characters from s'''
    pass

user_string = input("Please enter a string: ")
upper_chars = show_upper(user_string)
print(upper_chars)
```

### Explanation

1. **Function Definition**:
   - `show_upper(s)`: This function is designed to process the input string `s` and extract all the upper-case characters.

2. **Docstring**:
   - Describes the purpose of the function to return upper-case characters from the input string `s`.

3. **Main Program Flow**:
   - `user_string`: Prompts the user to input a string.
   - `upper_chars`: Calls the `show_upper` function, passing the `user_string` as an argument, and stores the result.
   - `print(upper_chars)`: Outputs the result to the console.

### Task
Implement the logic inside `show_upper` to return the upper-case letters from the input string.
Transcribed Image Text:### Objective Complete the function `show_upper`. This function takes one parameter - a string (`s`). It should return a string made up of all the upper-case characters in `s`. For example, if `s` is `"aBdDEfgHijK"`, then `show_upper` should return `"BDEHK"`. It should return the upper-case string - not print it. Do not change anything outside `show_upper`. ### Code ```python def show_upper(s): '''Returns the upper case characters from s''' pass user_string = input("Please enter a string: ") upper_chars = show_upper(user_string) print(upper_chars) ``` ### Explanation 1. **Function Definition**: - `show_upper(s)`: This function is designed to process the input string `s` and extract all the upper-case characters. 2. **Docstring**: - Describes the purpose of the function to return upper-case characters from the input string `s`. 3. **Main Program Flow**: - `user_string`: Prompts the user to input a string. - `upper_chars`: Calls the `show_upper` function, passing the `user_string` as an argument, and stores the result. - `print(upper_chars)`: Outputs the result to the console. ### Task Implement the logic inside `show_upper` to return the upper-case letters from the input string.
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
Datatypes
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