• Non ci sono risultati.

Introduction to Computer Science Application Final Exam

N/A
N/A
Protected

Academic year: 2021

Condividi "Introduction to Computer Science Application Final Exam"

Copied!
1
0
0

Testo completo

(1)

Introduction to Computer Science Application Final Exam

Ugo Dal Lago

Marco Di Felice

June 12, 2009

Exercise 1.

Given a function fun, defined as follows:

def fun(a,b):

if (a>10):

return a+fun(a-1,b) elif (a<5):

return a+fun(a+1,b) else:

return b

Decide what is the value of the following three expressions: fun(3,7), fun(12,3) and fun(6,9)

Exercise 2.

What is the output of the following program?

a=[[5,10,2],1,2]

b=a[0]

a[2]=b[1]

b[1]=[1,7,8]

c=b[2]

(a,b)=(b,a) print a print b print c Exercise 3.

Write a function splitList which takes two arguments, a list l and a natural number n, and returns a third list r. r is obtained by splitting l into pieces of length (at most) n and preserving the order. For example splitList([1,4,12,2,3,7,8],2) should re- turn [[1,4],[12,2],[3,7],[8]].

Exercise 4.

A teacher keeps track of grades in a registry, which can be modeled by a dictionary grades.

If a student’s name is a string a, then grades[a]

is a list of floating point numbers between 0

[email protected]

[email protected]

and 10, representing the grades obtained by a.

Write

(i) A function Insufficient(grades) which, given a registry grades returns the number of students which have at least one insuf- ficient grade (a grade is considered insuffi- cient if if it strictly less than 6).

(ii) A function Average(gradesone,gradestwo) which returns a registry obtained by merging two registries gradesone and gradestwo.

Exercise 5.

Bidimensional matrices of natural numbers can be easily represented as nested lists. For exam- ple, the matrix

 7 4 3 5 1 11



can be represented as the list [[7,4,3],[5,1,11]]. Write a func- tion transposeMatrix which trans- pose the matrix in input. For example transposeMatrix([[7,4,3],[5,1,11]]) should return the list [[7,5],[4,1],[3,11]].

1

Riferimenti

Documenti correlati

Now we locate all the zeros

[r]

By using the function safeDistance(tl,car) defined above, write a function move(tl,car,tstep) which takes a TLight object and a Car object as arguments and updates the car’s

Nella pratica clinica, si misura la velocità di flusso mediante Doppler intracoronarico, piuttosto che misurare il flusso assoluto, ragion per cui il parametro più

● Control unit (also known as CU) reads data from the instruction memory and data executes the instructions and copies the results to memory or

This article describes the state of informatics education in the Italian secondary schools, highlighting how the learning objectives set up by the Ministry of Education are difficult

Urakawa: Rigidity of transversally biharmonic maps between foliated Riemannian manifolds, to appear in Hokkaido Math.. [36] Ye-Lin Ou and Liang Tang: The generalized Chen’s

It can be seen that patients in phase ON tended to under- estimate the time interval that had to be measured, with respect to controls; the same patients, however,