ddddd August 13, 2020 By Paul Browning 1. "What does the following code print to the console? a = s = b = c = 1s = 2b = 3print(a) " "1""2""3""Exception"Question 1 of 50 2. "What does the following code print to the console? a, b, c, d = 0, 0, 0.0, 0e = f = g = h = 0print((a, b, c, d) == (e, f, g, h)) " "False""True""Exception because of line: a, b, c, d = 0, 0, 0.0, 0""Exception because of line: e = f = g = h = 0"Question 2 of 50 3. "What does the following code print to the console? string1 = 'hello'string2 = 'hello'string3 = ''' hello '''print(string1 == string2 == string3) " "True""False""Exception because of line: string1 = 'hello'""Exception because of line: string3 = """hello""""Question 3 of 50 4. "What does the following code print to the console? string1 = 'hello hello 'string2 = 'hello '*2print(type(string1) == type(string2)) " "True""False""Exception because of line: string2 = "hello "*2""Exception because of line: print(type(string1) == type(string2))"Question 4 of 50 5. "What does the following code print to the console def multiplication(a, b, c): return a * b * ca = 55b = 10.0c = Falseprint(multiplication(a, b, c)) " "550.0""550""0.0""Exception because of line: return a * b * c"Question 5 of 50 6. "What does the following code print to the console? s = 'The quick brown fox'a = 'Hot dog'a = sa = a[:-3] s[-3:]print(a) " "The quick brown fox""The quick brown dog""Hot fox""Exception because of line: a = a[:-3] s[-3:]"Question 6 of 50 7. "We have a python dictionary that stores the names of vegetables and their prices. We need to buy 3 carrots, 2 pears ans 1 orange. Select the code that gets the price sum correctly. shop = {'fruits': [{'orange': '$3'}, {'pear': '$2.05'}], 'vegetables': {'potato': '$1', 'carrot': '$1.5'}} " "float(shop['fruits'][1]['pear'].replace('$', '')) float( shop['fruits'][0]['orange'].replace('$', '')) 3 * float(shop['vegetables']['carrot'].replace('$', ''))""2 * float(shop['fruits'][1]['pear'].replace('$', '')) float( shop['fruits'][0]['orange'].replace('$', '')) 3 * float(shop['vegetables']['carrot'].replace('$', ''))""2 * float(shop['fruits']['pear'].replace('$', '')) float( shop['fruits']['orange'].replace('$', '')) 3 * float(shop['vegetables']['carrot'].replace('$', ''))""2 * float(shop['fruits'][1]['pear'].replace('$', '')) float( shop['fruits'][0]['orange'].replace('$', '')) 3 * float(shop['vegetables'][0]['carrot'].replace('$', ''))"Question 7 of 50 8. "What does the following code print to the console? a = 'Rotator'b = a[::-1]c = a[-1] a[-2] a[-3] a[-4] a[-3] a[-2] a[-1]d = a[:3] 'a' a[:3][::-1]print(a.lower() == b.lower() == c.lower() == d.lower()) " "False""True""Exception because of line: d = a[:3] 'a' a[:3][::-1]""Exception because of line: b = a[::-1]"Question 8 of 50 9. "What does the following code print to the console? a = Trueb = Falsec = a | be = 1if a & b or c == 1 and c is e: print('Hello!')elif c is not e or b: print('How are you?')else: print('I`m fine!') " "Hello!""How are you?""I`m fine!""Exception"Question 9 of 50 10. "What does the following code print to the console? days = ['Monday', 'Friday', 'Sunday']age = 20if (days.count('Monday') or 'Tuesday' not in days[:2]) and age >= 2: print('1') age = ''*100 if age: print('3') else: print('4')else: print('2') age = {} if age: print('5') else: print('6') " "26""13""25""1 4"Question 10 of 50 11. "What does the following code print to the console? a = 5if (True if 5 >= 0 else False) or (False if 5 >= 0 else True): print('1') if a in range(-5,5): print('3') else: print(4)else: print('2') if a in range(5): print('5') else: print(6) " "13""14""25""26"Question 11 of 50 12. "What does the following code print to the console? a = ('a', [1, 2, 3], 'b', {'a': 3})if type(a) == 'dict' and a[3]['a'] == '3': print('1')elif type(a[0]) == 'str': print('2')elif a[0] * a[1][2] == 'aaa': print('3')else: print('4') " "1""2""3""4"Question 12 of 50 13. "Which of the listed operators should we use here (a [operator] b) to get the largest number? a = 5b = 4 print(a [operator] b) " " ""*""**""<<"Question 13 of 50 14. "Which of the listed operators should we use here (a [operator] b) to get the smallest number? a = -2b = 4print(a [operator] b) " "-""%""<<"">>"Question 14 of 50 15. "Which of the listed operators should we use instead of {operator} to get 'Success' printed? a = ['a', 'b', 'c']b = ['a', 'b', 'c'] if a[1] {operator} b[1] and a {operator} b: passelse: print('Success!!') " "==""is "">=""<="Question 15 of 50 16. "What does the following code print to the console? a = 2b = 3if a|b is (a&b): print(a<<b)else: print(a*b) " "16""6""9""0"Question 16 of 50 17. "What does the following code print to the console? a = 10if a > 8: a = 10if a > 18: a = 10if a > 28: a = 10elif a > 38: a = 10if a > 48: a = 10if a > 58: a = 10print(a) " "10""40""60""70"Question 17 of 50 18. "What does the following code print to the console? i = 7for i in range(5): if i < 7: i =1print(i) " "5""7""13""12"Question 18 of 50 19. "What does the following code print to the console? a = 5do: a-=2while a <= 0 print(a) " "3""1""-1""SyntaxError"Question 19 of 50 20. "What does the following code print to the console? i = 20for i in range(10): while True: i = 2 if i == 15: breakprint(i) " "20""Nothing, because of infinite loop""14""10"Question 20 of 50 21. "What does the following code print to the console? for i in range(15): for item in ['cat', 'dog', 'hamster']: if i == 3: continue if i == len(item): result = 1print(result) " "15""3""1""6"Question 21 of 50 22. "What does the following code print to the console? items = ['a', 'b', 'c', 'd']for i in range(len(items)): for item in items: item = '-'print(items) " "['-', '-', '-', '-']""['a', 'b', 'c', 'd']""Exception""['a', 'b', 'c', '-']"Question 22 of 50 23. "What does the following code print to the console? def func(a, b): c = a bc = 0for i in range(1, 5): c = func(c, i)print(c) " "10""15""0""Exception"Question 23 of 50 24. "What does the following code print to the console? items = []i = 0while i == 0: for i in range(2): while True: items.append('*') i = 2 if len(items) == 5 or len(items) == 7: break break " "[]""['*', '*']""['*', '*', '*', '*']""['*', '*', '*', '*', '*', '*', '*']"Question 24 of 50 25. "The following code has an error, which line is it on? 1: f = open('demofile.txt', 'r')2: a = f.readline()3: b = f.read()4: f.write('Hello!')5: f.close() " "2""3""4""5"Question 25 of 50 26. "What does the following code print to the console? ('demofile.txt' exists. Size of the file: 64 kb) 1: file = open('demofile.txt', 'rb')2: a = file.read()3: file.close()4: a = a[2:4]5: file = open('demofile.txt', 'rb')6: b = file.read(2)7: c = file.read(2)8: file.close()9: print(a==c) " "False""True""Exception because of the line 2""Exception because of the line 6"Question 26 of 50 27. "You need to check if some file exists in file system, how do you do it?" "import osfile_path = 'demofile.txt'if os.path.exists(): file = open('demofile.txt', 'rb') file.close()""from os import pathfile_path = 'demofile.txt'if os.path.exists(): file = open('demofile.txt', 'rb') file.close()""import osfile_path = 'demofile.txt'if os.exists(): file = open('demofile.txt', 'rb') file.close()""file = open('demofile.txt', 'rb')file.close()"Question 27 of 50 28. "You need to check if some file exists and delete them, how do you do it?" "from os import removefile_path = 'demofile.txt'if os.exists(file_path): os.remove(file_path)""import osfile_path = 'demofile.txt'if os.exists(file_path): os.remove(file_path)""import osfile_path = 'demofile.txt'if os.path.exists(file_path): os.remove(file_path)""import osfile_path = 'demofile.txt'if os.path.exists(file_path): os.delete(file_path)"Question 28 of 50 29. "You need to safely get acces to the second comsole argument, how do you do it?Example:$python3 script.py 'A' 'B' 'C'You need to access 'B'" "import sysif len(sys.argv) > 1: second_argument = sys.argv[1]else: second_argument = 'default'""import sysif len(sys) > 2: second_argument = sys.argv[2]else: second_argument = 'default'""import sysif len(sys.argv) > 2: second_argument = sys.argv[2]else: second_argument = 'default'""import sysif len(sys.argv) > 3: second_argument = sys.argv[3]"Question 29 of 50 30. "You are asking the user to enter an integer number between 1 and 30, inclusive, into the console.What code validates this input correctly?" "while True: result = input("Please enter number from 1 to 30\n") if result.isdigit(): if int(result) in range(1,31): print("Thank you!") break print("Please try again") continue""while True: result = input("Please enter number from 1 to 30\n") if result.isdigit(): if result in range(1,31): print("Thank you!") break print("Please try again") continue""while True: result = input("Please enter number from 1 to 30\n") if result.isdigit(): break if int(result) in range(1,31): print("Thank you!") print("Please try again") continue""while True: result = input("Please enter number from 1 to 30\n") if result.isdigit(): if int(result) in range(0,31): print("Thank you!") break print("Please try again") continue"Question 30 of 50 31. "You have list of lists: a = [['1', '2', '3'], ['4', '5', '6'], '7'] What is the correct way to get '1|2|3;4|5|6;7' printed?" "print('|'.join([';'.join(x) for x in a]))""print(','.join([':'.join(x) for x in a]))""print(';'.join(['|'.join(x) for x in a]))""print(a)"Question 31 of 50 32. "The following code has an error, which line is it on? 1: ##this is a comment2: #this is a comment3: '''this is a comment'''4: '''5: this is a comment6: '''7: //this is a comment " "1""3""4,5,6""7"Question 32 of 50 33. "The following code has an error, which line is it on? 1: #comment2: a = 53: #comment4: a = 75: '''comment''' 6: a = 97: '''8: comment9: ''' " "1""3""5""3 and 5"Question 33 of 50 34. "What does the following code print to the console? 1: def func1(a, b):2: '''3: :param a:4: :param b:5: :return:6: '''7:8: for i in range(5):9: #increment a10: a =b11: ''':return a'''12: '''return a'''13: return a14:15:c = func1(3, 5)16:print(c) " "23""28""Exception because of line: 9""Exception because of line: 11"Question 34 of 50 35. "What does the following code print to the console? def func1(a=5, b=6, c): return a*b*ca = func1(2)print(a) " "60""18""10""SyntaxError"Question 35 of 50 36. "What does the following code print to the console? def func1(*args): return argsa = func1('a', 'c')print(a) " "['a', 'c']""('a', 'c')""{'a':0, 'c':1}""Exception"Question 36 of 50 37. "What does the following code print to the console? def func1(a, b, c=5, d=-1): a = a b*c if a > 10: return a*b return c*da = func1(2,1)b = func1(3,2)print(a == b)print(a is b) " "TrueTrue""FalseFalse""TrueFalse""FalseTrue"Question 37 of 50 38. "What does the following code print to the console? def func1(a, b, *args): a = (a 10)*args[0] return adef func1(a, b, c = 6): return ca = func1(1,2,3)print(a) " "33""3""99""Exception"Question 38 of 50 39. "Which exception will the following code raise? def func1(a, b, c=6): a = a-c b = c/a*2 return ba = 6b = 2c = func1(a, b) " "ZeroDivisionError""ArithmeticError""AssertionError""TypeError"Question 39 of 50 40. "Which exception will the following code raise? people_list = ['Joe', 'Markus', 'Jennifer']for item in people_list: next = people_list.index(item) 1 print('{} and {} are friends!'.format(item, people_list[next])) " "AttributeError""AttributeError""IndexError""TypeError"Question 40 of 50 41. "Which exception will the following code raise? a = 'quick brown fox jumps over the lazy dog'a = a[:-3] 'fox'a[-3:] = 'fox'print(a) " "IndexError""TypeError""ValueError""IOError"Question 41 of 50 42. "What does the following code print to the console? dict1 = {'a':'1', 'b':'2'}dict2 = {'a':'3', 'b':'4'}type = 'dictionary'for k, v in dict1.items(): dict2[k] = dict1[k]print(type(dict1['a']) == type(dict2['a'])) " "True""False""TypeError""ValueError"Question 42 of 50 43. "What does the following code print to the console? def check_exception(a): try: c = a/0 except ZeroDivisionError: print('1') else: print('2') c = 2 finally: c = 3 print('3') print('4') return ca = check_exception(5)print(a) " "1343""1243""10""133"Question 43 of 50 44. "Which code correctly handles the import of a non-existent module?" "try: import module_not_existsexcept ModuleNotFoundError as e: print("Module not found")""try: import module_not_existsexcept RuntimeError as e: print("Module not found")""try: import module_not_existsexcept TypeError as e: print("Module not found")""try: import module_not_existsexcept FutureWarning as e: print("Module not found")"Question 44 of 50 45. "What does the following code print to the console? def check_exception(): try: raise Exception('1') except ValueError as e: print(str(e)) print('2') finally: print('3')check_exception() " "123""23""Exception: 13""3"Question 45 of 50 46. "What is the correct way to create combo of random color and number from 1 to 22 using code given? import randomcolors = ['Red', 'Green', 'Blue'] " ""{}-{}".format(random.choice(colors), random.randint(1, 22))"""{}-{}".format(random.select(colors), random.randint(1, 22))"""{}-{}".format(random.choice(colors), random.randint(0, 22))"""{}-{}".format(random.choice(colors), random.randint(1, 23))"Question 46 of 50 47. "What does the following code print to the console? import matha = 2.9b = 2.95c = math.abs(a*b)print(c) " "8""9""Exception: AttributeError""Exception: TypeError"Question 47 of 50 48. "What is the correct way to get new path without folderD: 'C:/folderA/folderB/folderC/myfile.zip'? import ospath = 'C:/folderA/folderB/folderC/folderD/myfile.zip' " "folder_path = os.path.dirname(os.path.dirname(path))print(os.path.join(folder_path, path))""file = os.path.basename(path)folder_path = os.path.dirname(os.path.dirname(path))print(os.path.join(folder_path, file))""file = os.path.filename(path)folder_path = os.path.dirname(os.path.dirname(path))print(os.path.join(folder_path, file))""file = os.path.filename(path)folder_path = os.path.normpath(os.path.dirname(path))print(os.path.join(folder_path, file))"Question 48 of 50 49. "How many full years have passed since that date?Which function does this correctly? import datetimeborn = datetime.datetime(1960, 5, 17)years_now = get_age(born)print(years_now) " "def get_age(born): now = datetime.datetime.now() return (now.year-born.year)""def get_age(born): now = datetime.date.today() years = now.year - born.year if now.month < born.month or (now.month == born.month and now.day < born.day): years = years - 1 return years""def get_age(born): now = datetime.datetime.now() return (now-born).year""def get_age(born): now = datetime.date.today() years = now.year - born.year if now.month < born.month or (now.month == born.month and now.day < born.day): years = years 1 return years"Question 49 of 50 50. "What is the lowest and highest possible value of 'result'? import randomnumbers = [1, 2, 3, 4]result = random.randint(2, 4)*random.randint(1, 3)*random.choice(numbers[0:2])/random.choice(random.shuffle(numbers))print(result) " "0.5, 24.0""1, 12.0""2, 24.0""1, 3"Question 50 of 50 Loading...