My Report

Python Programming Practice Test 5


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Is the following Python code valid?

>>> a=(1,2,3)
>>> b=('A','B','C')
>>> c=tuple(zip(a,b))

2. What will be the output of the following Python code snippet?

z=set('abc$de')
'a' in z

3. What will be the output of the following Python code?

s1={3, 4}
s2={1, 2}
s3=set()
i=0
j=0
for i in s1:
    for j in s2:
        s3.add((i,j))
        i+=1
        j+=1
print(s3)

4. What will be the output of the following Python code?

>>> a={4,5,6}
>>> b={2,8,6}
>>> a-b

5. Which of the following is not the correct syntax for creating a set?

6. What will be the output of the following Python code?

s1={1, 2, 3, 8}
s2={3, 4, 5, 6}
s1|s2
s1.union(s2)

7. What will be the output of the following Python code snippet?

>>> a={1:"A",2:"B",3:"C"}
>>> del a

8. What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}
print(a.get(5,4))

9. What will be the output of the following Python code snippet?

l=[1, 2, 4, 5, 2, 'xy', 4]
set(l)
l

10. What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.