Returns a copy of numList with all the occurrences of old replaced by new. The process should not mutate the original list (alter the memory block referenced by numList). You can assume numList is a list of numbers and that old and new are either int or float. You are not allowed to use any replace methods from the Python library. Input numList A list of numbers A number A number list int/float old int/float | new Output Copy of numList with all the occurrences of old replaced by new list [1, 7, 5.6, 3, 2, 4, 1, 9] >>> input_list >>> replace (input_list, 1, 99.9) [99.9, 7, 5.6, 3, 2, 4, 99.9, 9] >>> input_list [1, 7, 5.6, 3, 2, 4, 1, 9] >>> replace([1,7, 5.6, 3, 2, 4, 1, 9], 5.6, 777) [1, 7, 777, 3, 2, 4, 1, 9] >>> replace([1,7, 5.6, 3, 2, 4, 1, 9], 8, 99) [1, 7, 5.6, 3, 2, 4, 1, 9]

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In python 

two possible ways please 

### Function Description

This function returns a copy of `numList` with all the occurrences of `old` replaced by `new`. The original list must remain unchanged (no mutation of `numList`). You can assume `numList` is a list of numbers, where `old` and `new` are either integers or floats. The use of any Python library replace methods is not allowed.

#### Input Parameters

- **list** `numList`: A list of numbers.
- **int/float** `old`: A number to be replaced.
- **int/float** `new`: The number to replace `old`.

#### Output

- **list**: Returns a copy of `numList` with all occurrences of `old` replaced by `new`.

### Examples

```python
>>> input_list = [1, 7, 5.6, 3, 2, 4, 1, 9]
>>> replace(input_list, 1, 99.9)
[99.9, 7, 5.6, 3, 2, 4, 99.9, 9]

>>> input_list
[1, 7, 5.6, 3, 2, 4, 1, 9]

>>> replace([1, 7, 5.6, 3, 2, 4, 1, 9], 5.6, 777)
[1, 7, 777, 3, 2, 4, 1, 9]

>>> replace([1, 7, 5.6, 3, 2, 4, 1, 9], 8, 99)
[1, 7, 5.6, 3, 2, 4, 1, 9]
```

### Explanation of Example Outputs

1. **Replace the number `1` with `99.9`:**
   - The number `1` appears twice in `input_list` and is replaced with `99.9` in the new list. The original list is unchanged.

2. **Demonstrating the function with other numbers:**
   - Replace `5.6` with `777`: The number `5.6` is found and replaced.
   - Attempt to replace `8` with `99`: The number `8` is not in
Transcribed Image Text:### Function Description This function returns a copy of `numList` with all the occurrences of `old` replaced by `new`. The original list must remain unchanged (no mutation of `numList`). You can assume `numList` is a list of numbers, where `old` and `new` are either integers or floats. The use of any Python library replace methods is not allowed. #### Input Parameters - **list** `numList`: A list of numbers. - **int/float** `old`: A number to be replaced. - **int/float** `new`: The number to replace `old`. #### Output - **list**: Returns a copy of `numList` with all occurrences of `old` replaced by `new`. ### Examples ```python >>> input_list = [1, 7, 5.6, 3, 2, 4, 1, 9] >>> replace(input_list, 1, 99.9) [99.9, 7, 5.6, 3, 2, 4, 99.9, 9] >>> input_list [1, 7, 5.6, 3, 2, 4, 1, 9] >>> replace([1, 7, 5.6, 3, 2, 4, 1, 9], 5.6, 777) [1, 7, 777, 3, 2, 4, 1, 9] >>> replace([1, 7, 5.6, 3, 2, 4, 1, 9], 8, 99) [1, 7, 5.6, 3, 2, 4, 1, 9] ``` ### Explanation of Example Outputs 1. **Replace the number `1` with `99.9`:** - The number `1` appears twice in `input_list` and is replaced with `99.9` in the new list. The original list is unchanged. 2. **Demonstrating the function with other numbers:** - Replace `5.6` with `777`: The number `5.6` is found and replaced. - Attempt to replace `8` with `99`: The number `8` is not in
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY