## Question

Q1. Write a python program to calculate 1 - 1/2 + 1/3 - 1/4 + + 1/99 - 1/100. until the absolute value of the last term is less than 10-3 (do not include this term that less than 10-3 in your calculation.

Q2. Given a list of integer numbers. Implement the following function to remove the duplicates. For example, if numbers = [1, 9, 3, 12, 11, 1, 3, 3, 21], then remove_duplicates(numbers) should return a list [1, 9, 3, 12, 11, 21]. You should not change the relative order of numbers in your returned list.

def fremove_duplicates(numbers):

Q3. Given a string of characters and digits. Implement the following function to count the number of characters and digits. For example, if str = "hello123!" count_stuff(str) should return a dictionary {'letters': 6, "digits': 3}

def count_stuff(str):

Q4. You should be able to find an exercises.csv in the attachment. This file includes a bunch of students, their attempts and the corresponding responses. It has the following

format:

number of attempts

the exercise ids

the responses (0 or 1)

For example:

5

120, 3, 5, 9, 6

1, 1, 1, 0, 1

3

100, 3, 9

1, 0, 0

The above includes the information for two different students. The first student has 5 attempts, the exercise ids are 120, 3, 5, 9, 6. And the results (responses) are 1, 1, 1, 0, 1 (here 0 means incorrect, 1 means correct). The second student has 3 attempts, the exercise ids are 100, 3, 9 and the results (responses) are 1, 0, 0.

Implement the following python function to load all these information. load_data should return a list in the following format

[([attempts], [exercises], [responses]) ...]

in our example above, it should return

[([5], [120, 3, 5, 9, 6], [1, 1, 1, 0,1]), ([3], [100, 3, 9], [1, 0, 0])]. Do not return students

whose attempts are less than 3.

def load_data(filename):

Q5. Use the data returned from Q4, Write a python program to get the max attempts among all students (you need to find the student who has the most attempts and return the number of his attempts), as well as the number of different exercises (how many different exercise ids are there?)

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import csvimport numpy as np

# Question 1

def sum():

i = 1

sm = 0.0

term = 0.0

while 1 / i >= pow(10, -3):

sm = sm + pow(-1, (i + 1)) * (1 / i)

i = i + 1

return sm

print("Q1")

# Test

print("The sum is equal to: ", sum())

print("The sum on 3 decimal places: ", round(sum(), 3))

print("")

# Question 2

def remove_duplicates(numbers):

new_list = []

for k in numbers:

if k not in new_list:

new_list.append(k)

return new_list...