Professional Documents
Culture Documents
2 Strings Lists Functions
2 Strings Lists Functions
2 Strings Lists Functions
Full Name:
Email:
scored in Ing. Fis. 2021/2022
100%
Test Name: Ing. Fis. 2021/2022 Seconda esercitazione Seconda esercitazione in
45/45 105394 min 59 sec on 26 Oct
Taken On: 26 Oct 2021 15:50:46 CEST 2021 15:50:46 CEST
Time Taken: 105394 min 59 sec/ 90 min
Skills Score:
Strings 15/15
list 26/26
Recruiter/Team Comments:
No Comments.
Correct Answer
QUESTION DESCRIPTION
The goal of this assignment is to write the function edi t _ l i st ( l ) that takes in input a list of integer
Score 25
numbers: l
edi t _ l i st ( l ) must:
1. Normalize all the elements of l dividing them by the sum of all the initial values of l . Note:
1/6
1. This must be done editing l in place, not on a copy
2. if l is empty or the sum is zero you should not modify it.
2. Return a list containing the even elements of l . The order is not relevant.
For example:
l = [1,4,2,5,3,1,4]
res = edit_list(l)
CANDIDATE ANSWER
1 #
2 # Complete the 'edit_list' function below.
3 # Take in input a list of integer number (l)
4 #
5
6
7 def edit_list(l):
8 even = []
9 my_sum = 0
10 # Write your code here
11 for i in range(len(l)):
12 if l[i] % 2 == 0:
13 even.append(l[i])
14
15 for j in range(len(l)):
16 my_sum += l[j]
17 for k in range(len(l)):
18 l[k] = l[k]/my_sum
19
20
21 return even
22
No Comments
Correct Answer
QUESTION DESCRIPTION
then:
CANDIDATE ANSWER
1 #
2 # Complete the 'manipulate' function below.
3 #
4 # The function is expected to return a 2D_STRING_ARRAY.
5 # The function accepts following parameters:
6 # 1. STRING_ARRAY str_list
7 # 2. INTEGER k
8 # 3. CHARACTER c
9 #
10
11 def manipulate(str_list, k, c):
12 k_words = []
13 other_words = []
14 counter = 0
15 # Write your code here
16 for i in range(len(str_list)):
17 if str_list[i][0] == c:
18 k_words.append(str_list[i])
19 if len(k_words) > k:
20 del k_words[k:len(k_words)]
21 for i in range(len(str_list)):
22 if str_list[i] not in k_words:
23 other_words.append(str_list[i])
24
25 return k_words, other_words
Testcase 0 Easy Sample case Success 7.5 / 7.5 0.0512 sec 9.4 KB
Testcase 1 Easy Sample case Success 7.5 / 7.5 0.065 sec 9.4 KB
No Comments
3/6
QUESTION 3 Strings formatting
Multiple Choice
What is the format specifier to print a floating number with 3 units and 2 decimals?
Score 1
CANDIDATE ANSWER
:2.3f
2:3.f
:3.2f
3:2.f
No Comments
res = func(10,c=4)
CANDIDATE ANSWER
17
16
15
14
No Comments
4/6
QUESTION 5 Return values
Multiple Choice
Correct Answer
QUESTION DESCRIPTION
def func():
return 1,2
a = func()
CANDIDATE ANSWER
(1,2)
[1,2]
"1,2"
No Comments
Correct Answer
QUESTION DESCRIPTION
s = ['t','a','g','j','r']
print(s.sort())
CANDIDATE ANSWER
None
ValueError
No Comments
5/6
QUESTION 7 Slices
Multiple Choice
Correct Answer
QUESTION DESCRIPTION
Given that:
Score 1
a = [1,2,3,4,5]
b = [5,6,7]
CANDIDATE ANSWER
a[5] == b[1]
a[7] == b[0]
a[-1] == b[-1]
a[4:7] == b[:1]
No Comments
6/6