0% found this document useful (0 votes)
8 views5 pages

Questions On Python Lyst1714549069108

The document contains a series of programming questions related to Python, including code snippets and multiple-choice answers. Each question tests knowledge of Python functions, variable scope, and output of code. The answers to the questions are provided at the end.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Questions On Python Lyst1714549069108

The document contains a series of programming questions related to Python, including code snippets and multiple-choice answers. Each question tests knowledge of Python functions, variable scope, and output of code. The answers to the questions are provided at the end.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Q1.

def fun1(l1, l2):


l3 = []
for i in range(len(l2)):
l3.append(l2[i])
for i in range(len(l1)):
l3.append(l1[i])
return l3
l1 = [10, 20, 30]
l2 = [50, 60, 70]
print(fun1(l1, l2))
what is the output of above code?
A) [10, 20, 30] B) [50, 60, 70]
C) [10, 20, 30, 50, 60, 70] D) [50, 60, 70, 10, 20, 30]

Q2: Given below the python code:


def fun1(l1):
l2 = []
while(len(l1) > 0):
minn = l1[0]
for i in range(1, len(l1)):
if l1[i] > minn:
minn = l1[i]
l2.append(minn)
l1.remove(minn)
return l2
l1 = [10, 5, 20, 21, 13, 1]
print(fun1(l1))
A) It will print the list in increasing order
B) It will print the list in decreasing order
C) It will print the minimum element from the list
D) It will print the maximum element from the list
Q3. Which of the following is a valid variable name in Python?
A) 2variable B) my-variable
C) _myVariable D) my Variable

Q4. What is the scope of a variable in Python?


A) The range of values that the variable can take
B) The lifetime of the variable during program execution
C) The area of code where the variable is accessible
D) The data type of the variable

Q5. What will be the output of the following code snippet?


x=5
y=x
x = 10
print(y)
A) 5 B) 10 C) Error D) None

Q6. What will be the output of the following code snippet?


def count_down(n):
print(n)
if n > 0:
count_down(n-1)
count_down(5)
A) 5 4 3 2 1 0 B) 5 4 3 2 1
C) 1 2 3 4 5 0 D) 0 1 2 3 4 5
Q7. What will be the output of the following code snippet?
def fibonacci(n):
if n <= 1:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)
print(fibonacci(6))
A) 6 B) 8 C) 13 D) 21

Q8. What will be the output of the following code snippet?


def power(x, y=2):
return x ** y

print(power(2))
print(power(2, 3))
A) 4, 8 B) 4, 9
C) 8, 4 D) 9, 4

Q9. What will be the output of the following code snippet?


def greeting(name):
return f"Hello, {name}!"
print(greeting("Alice"))
print(greeting("Bob", "Johnson"))
A) Hello, Alice! Error
B) Error Hello, Bob Johnson!
C) Hello, Alice! Hello, Bob Johnson!
D) Error Error
Q10. What will be the output of the following code snippet?
def square(x):
return x ** 2
numbers = [1, 2, 3, 4]
squares = list(map(square, numbers))
print(squares)
A) [1, 4, 9, 16]
B) [1, 2, 3, 4]
C) [1, 1, 1, 1]
D) [2, 4, 6, 8]

Q11. What will be the output of the following code snippet?


x = 10
def foo():
x=5
print(x)
foo()
print(x)
A) 5, 10
B) 10, 5
C) 5, 5
D) 10, 10
Ans:
1. D
2. B
3. C
4. C
5. A
6. A
7. C
8. A
9. D
10. A
11. A

You might also like