python exam 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

#what will be the output of the following code? >>> t = (1, 2) >>>2*t

(1,2,1,2)

#what will be the output of: t=(1,2,4,3) t[1:3]

(2,4)

#what will be the output? t=(1,2,4,3) t[1:-1]

(2,4)

#what is the output of the following code? test = {1:'A', 2:'B', 3:'C'} test = {} print(len(test))

0

#what will be the output of the following python code? test = {1:'A' , 2:'B' , 3:'C'} test = {} print(len(test))

0

#what is the output of the following? i= 1 while i< 5 print(i) I +=1

1 2 3 4

#what is the output of the following python code? def main(): myList = [1,2,3,4,5] for x in ,myList: print(x*x) main()

1 4 9 16 25

#what is the output of the following python code? def main(): p = [] p = [1,2,'python'] p[1] = '100' p.append('is the best') print(p) main()

1, 100, python is the best

#suppose list1 is [3,4,5,20,3], what is list1.index[5] ?

2

#suppose list1 is [3,4,5,20,3]. what is list1.count(3)?

2

#what is the output of the below program? def minimum(x,y) if x>y: return x elif x == y: return 'the numbers are equal' else return y print(minimum(2,3))

2

#suppose list1 is [2,33,222,14,25]. what is list1[-1]?

25

#what is the output of the below program? def maximum(x,y) if x>y: return x elif x == y: return 'the numbers are equal' else return y print(maximum(2,3))

3

#what will be the output of: numbergames = {} numbergames [(1,2,4)] = 8 numbergames [(4,2,1)] = 10 numbergames [(1,2,4)] = 10 numbergames [(1,2)] = 12 sum = 0 for k in numbergames: sum += numbergames [k] print(len(numbergames) + sum)

35

#what is the output of the following code? def main(): for i in range(4,10 +1, 2): print(i) main()

4 6 8 10

#what will be the output of the following python code? d = {'John':40, 'Peter':45} d['John']

40

#what is the output of the following code? list1 = [1,3,5,7] list2 = list1[:] list1[0]=4 print(list2)

[1,3,5,7]

#what will the output of the following python code? a= [1 , 2, 3, 4, 5] for i in range(1,5): a[i-1] = a[i] print (a)

[2,3,4,5,5]

#suppose list1 is [2,33,222,14,25]. what is list[:-1]?

[2,33,222,14]

#what is the output of the following code? a={1:'A', 2:'B', 3:'C'} del a

deletes dictionary

#what will be the output of the following python code? >>>a={1:'A' , 2:'B', 3:'C'} >>> a.items()

dict_items([(1, 'A'), (2,'B'), (3,'C')])

#what is the output when following code is executed? names = ['Tom' , 'Jennifer' , 'Helen', 'Timothée'] print(names[-1][-1])

e

#what is the output of the following code? def main(): myData = (18,'Hello', 6, 'World') myData[2] = 4 print(myData) main()

error

#what is the output when following code is executed? list1 = [11,2,33] list2 = [11,2,2] print (list1 < list2)

false

#what is the output of the below program? def say(message, times): print(message * times) say('hello' , 1) say('world',5)

hello worldworldworldworldworld

#what type of data is: a=[(1,1),(2,4),(3,9)]?

list or list of tuples

#to remove string 'hello' from list1, we use which command?

list1.remove('hello')

#suppose t = (1,2,4,3) are you able to do t[3] = 45? Yes or no?

no

#is the following code valid? >>>a=(1,2,3,4) >>>del a yes or no?

yes

#suppose t = (1,2,4,3) are you able to do print(len(t))? Yes or no?

yes

#suppose t = (1,2,4,3) are you able to do print(max(t))? Yes or no?

yes

#suppose t = (1,2,4,3) are you able to do print(t[3])? Yes or no?

yes


Conjuntos de estudio relacionados

PP RNSG 1538 Intracranial Regulation Mastery Quiz

View Set

Chapter 4 - Entity Relationship (ER) Modeling

View Set