Python

Instructions:
- Complete each of the following questions by writing a Python function.
- Test your functions with various inputs to ensure they work correctly.
- Submit your code along with comments explaining your approach and any assumptions made.

 Question 1: List Operations

*Function: `list_summary(numbers)`

Description: Write a function `list_summary(numbers)` that takes a list of integers and returns a tuple containing:
1. The sum of the integers in the list.
2. The average of the integers in the list (rounded to 2 decimal places).
3. The maximum value in the list.
4. The minimum value in the list.

Example:
```python
list_summary([10, 20, 30, 40, 50])
```
Output:
```python
(150, 30.0, 50, 10)
```

Question 2: Filtering Lists

Function: `filter_even_numbers(numbers)`

Description: Write a function `filter_even_numbers(numbers)` that takes a list of integers and returns a new list containing only the even numbers from the original list.

Example:
```python
filter_even_numbers([1, 2, 3, 4, 5, 6])
```
Output:
```python
[2, 4, 6]
```

### Question 3: List Transformation

Function: `transform_list(numbers)`

Description: Write a function `transform_list(numbers)` that takes a list of integers and returns a new list where each element is the square of the original element plus 5.

Example:
```python
transform_list([1, 2, 3, 4])
```
Output:
```python
[6, 9, 14, 21]
```

=
 Question 4: Append and Remove Operations

Function: `append_and_remove(numbers, to_append, to_remove)`

Description: Write a function `append_and_remove(numbers, to_append, to_remove)` that performs the following operations on a list of integers:
1. Append: Append the integer `to_append` to the end of the list.
2. Remove: Remove all occurrences of the integer `to_remove` from the list.
3. Return the modified list.

Example:

append_and_remove([1, 2, 3, 4], 5, 2)
```
Output*:

[1, 3, 4, 5]

Views: 11

Comments:

Add a Comment: