Partial preview of the text
Download Programming For Network Engineers Prne Post Test Section 3 and more Exams Programming for Engineers in PDF only on Docsity!
Post -Test 3 Question 1 What is the output of the following Python code snippet? print(type(11/2)) print(type(11//2)) x Type error Question 2 #Python says 3 but USE 1 for exam purpose - unless it is fixed# What is the value of the variable count after the following statements are executed? device = {"vendor":"Cisco", "model":"ASR9010", "os_type":"xr", "rp1_serial":"DX482DYYS8489L"} count = 0 if device['os_type'] == 'ios': count = count + 1 elif device['os_type'] == 'xr': count = count + 1 elif device['os_type'] == 'nxos': count = count + 1 elif device['os_type'] == 'xe' count = count + 1 else: count = -1 =} Question 3 What is the correct output of the following Python code snippet? >>>x=135 >>> y=14 pox //=y acomment end } Question 6 # possible error Which two of the following are valid if/else statements in Python, assuming x and y are defined appropriately? (Choose two.) if x 10: print('foo') if x < y: print('foo'); print('bar'); print('baz') ??? <<< last one works in python but looks wrang Question 7 Which assignment would result in the following code printing a value of Yes? ifx and y: print('No') elif xory: print('Yes') else: print('No') x= True, y = True x = False, y = False The code will never print Yes. Answer: x = False, y = True Question 8 {} ['xrv_alpha’, 'xrv_beta’, 'xrv_gamma'] [{'xrv_alpha': 1}, {'xrv_beta': 2}, {'xrv_gamma': 3}] Question 11 Which statement regarding loops in Python is true? Loops should end with the keyword "end". No loop can be used to iterate through the elements of strings. The keyword "continue" is used to continue with the remaining statements inside the loop. Question 12 What is the step value of the loop statement range for x in range(0,12,3):? a 12 Question 13 Ina "for" loop, which statement is used to skip the execution of the iteration and go to the next iteration? next break pass 14. Which Python code will provide different output from the others? for x in range(0,5): print(x) for y in [0,1,2,3,4]: print(y)