My Report

Python Programming Practice Test 7


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. What will be the output of the following Python code?

l=[]
def convert(b):
    if(b==0):
        return l
    dig=b%2
    l.append(dig)
    convert(b//2)
convert(6)
l.reverse()
for i in l:
    print(i,end="")

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

odd=lambda x: bool(x%2)
numbers=[n for n in range(10)]
print(numbers)
n=list()
for i in numbers:
    if odd(i):
        continue
    else:
        break

3. In _______________ copy, the base address of the objects are copied. In _______________ copy, the base address of the objects are not copied.

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

l=[n for n in range(5)]
f=lambda x:bool(x%2)
print(f(3), f(1))
for i in range(len(l)):
    if f(l[i]):
        del l[i]
        print(i)

5. Which of the following is false about “from-import” form of import?

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

x = ['ab', 'cd']
print(len(map(list, x)))

7. Which is the most appropriate definition for recursion?

8. What is the base case in the Merge Sort algorithm when it is solved recursively?

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

x = [34, 56]
print(len(map(str, x)))

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

def to_upper(k):
    return k.upper()
x = ['ab', 'cd']
print(list(map(upper, x)))

 

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.