Programmering Final Exam fall 2022

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the output of the following program? x = ["Yesterday's", "Today's", "Tomorrow's"] y = ['temperature'] for i in x: if i[0] != 'T': for j in y: print (i, end=' ')

a. Today's Tomorrow's temperature b. Yesterday's temperature Tomorrow's temperature c. Yesterday's (Riktig) d. Yesterday's Today's Tomorrow's

What is the output of the following program? mylist = ['python', 'mek1300'] for i in mylist: i.upper () print (mylist) ** The upper () method returns a string where all characters are in uppercase. **

a. ['PYTHON', 'MEK1300'] b. ['python', 'mek1300']. (Riktig) c. ['Python', 'Mek1300'] d. [None, None]

What is the output of the following program? a = [] for x in [0, 1, 2]: for y in [3, 4, 5]: if x != y: a.append ((x,y)) print (a)

a. [0, 1, 2, 3, 4, 5] b. [(1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5)] c. [(0, 1, 2), (3, 4, 5)] d. [(0, 3), (0, 4), (0, 5), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5)]. (Riktig)

What is the output of the following program? x = [5, 4, 3, 2, 1] y = x.copy () print (y)

a. [1, 2, 3, 4, 5] b. [5, 4, 3, 2, 1] c. [0, 1, 2, 3, 4, 5] d. [ ]

What is the output of the following program?my_dictionary = {'a': [1, 2, 3], 'b': (4, 6, 8)} my_dictionary ['a'].append (4) print (my_dictionary ['a'], end = " ") my_list = [my_dictionary ['b']] my_list.append (10) my_dictionary ['b'] = tuple (my_list) print (my_dictionary ['b'])

a. [1, 2, 3, 4] [4, 6, 8, 10] b. [1, 2, 3, 4] ((4, 6, 8), 10). (Riktig) c. [1, 2, 3, 4] (4, 6, 8, 10) d. Error

What is the output of the following program? x = {0:4, 1:8, 2:16, 3:32} print (list (x.values ())[2])

a. [4, 8] b. [4, 8, 16] c. 16 (Riktig) d. 8

Which one of the following functions can be used to find the data type of an object in Python?

a. datatype () b. data () c. type (). (Riktig) d. true ()

Which one is correct regarding the use of id() function in python?

a. id () returns the identity of the object. (Riktig) b. Every object doesn't have a unique id c. All of the mentioned d. None of the mentioned

Which one of the following functions converts (if possible) a string x to a floating-point number in python?

a. int (x [, base]) b. long (x [, base]) c. float (x). (riktig) d. str (x)

What is the output of the following program? x = 25 if x > 10 and x <= 15: print ('true') elif x >= 15 and x < 25: print ('not true') elif x >= 25 and x < 35: print ('false') else: print ('not false')

a. true b. false. (Riktig) c. not true d. not false

A user-specified value can be assigned to a variable with the function

a. user () b. enter () c. input (). (Riktig) d. value ()

What is the output of the following statements? x = [24, 50, 37] y = 24 in x print (y)

a. x [0] b. 24 c. True. (Riktig) d. False

What is the output of the following program? x = {'x':1, 'y':2, 'z':3} for i in x: print (i, end=' ')

a. x y z. (Riktig) b. 1 2 3 c. x:1 y:2 z:3 d. True

What is the output of the following statements? x = 'Python' print (x[:])

a. yth b. Pn c.Python. (Riktig) d.PythonPythonPython

What is the output of the following program? set1 = {1, 2, 3} set2 = set1.add (4) print (set2)

a. {1, 2, 3} b. {1, 2, 3, 4} c. None (Riktig) d. Error

What is the output of the following program?my_set = {1, 2, 3, 4, 4}print (my_set)

a. {1, 2, 3} b. {1, 2, 3, 4} (Riktig) c. {1, 2, 3, 4, 4} d. Error

What is the output of the following program? b =3 for a in range (10, 1): b -= a + 1 print (b)

a.7 b. 4 c. 3 d. 8

What is the output of the following program? values = [1, 2, 3, 4, 5] try:value = values [5]/0 except (IndexError, ZeroDivisionError): print ('MEK1300 ', end = ' ') else:print ('Programming ', end = ' ') finally:print ('Python ', end = ' ')

a.MEK1300 b. MEK1300 Programming c. MEK1300 Python. (Riktig) d.MEK1300 Programming Python

43. What is the output after the following statement? print (a)

a. SyntaxError b. TypeError c. ValueError d. NameError (Riktig)

What is the output of the following statement? print (not (4 != 3))

a. True b. False. (Riktig) c. None d. Error

What is the output of the following program?my_string = 'MEK1300' for i in range (len (my_string)): print (my_string, end=" ") my_string = 'A

a. M A A A A A A b. MEK1300 A A A A A A. (Riktig) c. M E K 1 3 0 0 A A A A A A d. Error

What is the output of the following program? def xyz (): a = 56 xyz () print (a)

a. NameError. (Riktig) b. 56 c. xyz d. a=56

What is the output of the following program? my_list = ['Python', 'MEK1300', 'MEK', 'OsloMet'] position = my_list.index ("Oslo") print (position * 3)

a. Oslo Oslo Oslo b. Python c. Python Python Python d. ValueError: 'Oslo' is not in list (Riktig)

What is the output of the following program?

a. Python b. Python3 c. PythonPythonPython. (Riktig) d. Error

What is the output of the following statements? x = "Python %.1f or Python %.2f" % (2.7, 3.81) print (x)

a. Python 3.81 or Python 2.7 b. Python 2 or Python 3 c. Python 2.7 or Python 3.8 d. Python 2.7 or Python 3.81. (Riktig)

What is the output of the following program? temp = dict () temp ['a'] = {'a': 10, 'b': 20} temp ['b'] = [1, 2, 3, 4]for key, values in temp.items ():print (values, end = " ")

a. Error b. {'a': 10, 'b': 20} [1, 2, 3, 4]. (Riktig) c. [1, 2, 3, 4] {'a': 10, 'b': 20} d. True

Which one of the following data types is not a built-in data type in Python?

a. List b. Dictionary c. Tuple d. Class. (Riktig)

Python files are saved with the extension as

a. .python b. .pe c. .py. (Riktig) d. .p

What is the output of the following program? a = 27 / 3 % 2 * 4**2 print (a)

a. 0 b. 16.0. (Riktig) c. 32 d. 4.0

31. What is the output of the following program? x =0 while x < 10: print (x, end='') x += 4

a. 0123456789 b. 123456789 c. 4123456789 d. 048. (Riktig)

What is the output of the following program?counter = 1 def my_func (): global counterfor for i in (1, 2, 3): counter += 1 my_func () print (counter)

a. 1 b. 3 c. 4. (riktig) d. 2

What is the output of the following program? def abc (): global x x = 23 x = 10 abc () print (x

a. 10 b. 23. (Riktig) c. 0 d. NameError

What is the output of the following program? import randomprint (int (random.random() * 10))

a. 10 b. A random integer number within the range of 0 to 9. (Riktig) c. None d. A random floating point number within the range of 0 to 9

What is the output of the following program? for i in range (0, 5): if i == 2: break print (i, end=' ')

a. 12 b. 01. (Riktig) c. 012 d. 0123

What is the output of the following program? my_dictionary = {} my_dictionary [1] = 1 my_dictionary ['1'] = 2 my_dictionary [1] += 1 total = 0 for x in my_dictionary: total += my_dictionary [x] print (total)

a. 2 b. 3 c. 4. (Riktig) d. 5

What is the output of the following program? L1 = [1, 1.33, 'XYZ', 0, 'NO', None, 'A', True] val1, val2 = 0, '' for x in L1: if (type (x) == int or type (x) == float): val1 += x elif (type (x) == str): val2 += x else: break print (val1, val2)

a. 2 XYZNO b. 2.33 XYZNOA c. 2.33 XYZNONoneATrue d. 2.33 XYZNO. (Riktig)

41. What is the output of the following program? a = list (range (-10, 5, 2)) print (sum (a))

a. 24 b. 0 c. -24. (Riktig) d. 20

What is the output of the following statements? x = 3 y = 2 x += y print (x)

a. 3 b. 2 c. 5. (Riktig) d. 1

What is the output of the following program?my_tuple = ('1', 'b', 3, True) my_tuple.append (["Python", "MEK1300") print (len(my_tuple))

a. 4 b. 5 c. 6 d. Error. (Riktig)

What is the output of the following program? for i in [1, 2, 3, 4][: : -1]: print (i, end=" ")

a. 4 3 2 1 (Riktig) b. 1 2 3 4 c. 4 d. 1

What is the output of the following statements? x = 8 y = 2 print (x // y)

a. 4.0 b. 4. (Riktig) c. 16.0 d. 16

What is the output of the following program? my_list = [1, 2, 3, None, (1.2, 2.67, "3", True), ['Python', 'MEK1300', 'Programming']] print (len (my_list))

a. 5 b. 6. (Riktig) c. 10 d. 11

What is the output of the following program? values = [1, 2, 3, 4] values.append ([5, 6, 7, 8]) print (len (values), values)

a. 5 [1, 2, 3, 4, [5, 6, 7, 8]] (RIKTIG) b. 8 [1, 2, 3, 4, [5, 6, 7, 8]] c. 5 [1, 2, 3, 4, 5, 6, 7, 8] d. 8 [1, 2, 3, 4, 5, 6, 7, 8]

What is the output of the following program? L = [2, 4, 6, 8, 0]print (L.pop(-3), end = " ") print (L.remove(L[0]), end = " ") print (Lterm-13)

a. 6 2 [4, 8, 0] b. 6 None [4, 8, 0]. (Riktig) c. 6 None [2, 4, 8, 0] d. [4, 8, 0]

Which of the following is an assignment operator in Python?

a. == b. != c. > d. = (Riktig)


Ensembles d'études connexes

8. THE REFORMATION: ZWINGLI, GREBEL, CALVIN, AND KNOX

View Set

What Am I? Chapter 3 Control Devices

View Set

Retirement and Estate Planning Exam 3 practice questions

View Set

Contemporary Topics Chapter 10 + 11 Quiz

View Set

NUR 2092 Pharm Ch 43- Drugs affecting blood pressure

View Set

Biology Term 3 Test 3 Study Guide

View Set

Education and Health Savings Plans

View Set