Font size
WorksheetsPYTHON PROGRAMMING
Total questions: 15
Worksheet time: 5mins
1. What is the output of the following code?
var1 = 1
var2 = 2
var3 = "3"
print(var + var2 + var3)
6
33
123
ERROR
2. What is the output of the following code?
p, q, r = 10, 20 ,30
print(p, q, r)
10 20
10 20 30
Error: invalid syntax
3. What is the Output of the following code?
for x in range(0.5, 5.5, 0.5):
print(x)
[0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5]
[0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
The Program executed with errors
4. What is the output of the following code?
salary = 8000
def printSalary():
salary = 12000
print("Salary:", salary)
printSalary()
print("Salary:", salary)
Salary: 12000 Salary: 8000
Salary: 8000 Salary: 12000
The program failed with errors
5. What is the output of the following code?
def calculate (num1, num2=4):
res = num1 * num2
print(res)
calculate(5, 6)
20
The program executed with errors
30
6. Can we use the “else” clause for loops?
for example:
for i in range(1, 5):
print(i)
else:
print("this is else block statement" )
YES
NO
7. A string is immutable in Python?
Every time when we modify the string, Python Always creates a new String and assigns a new string to that variable.
TRUE
FALSE
8. What is the output of the following code?
sampleList = ["Jon", "Kelly", "Jessa"]
sampleList.append(2, "Scott")
print(sampleList)
The program executed with errors
[‘Jon’, ‘Scott’, ‘Kelly’, ‘Jessa’]
[‘Jon’, ‘Kelly’, ‘Scott’, ‘Jessa’]
9. What is the output of the following?
x = 36 / 4 * (3 + 2) * 4 + 2
print(x)
182.0
37
117
ERROR
10. Which operator has higher precedence in the following list?
% Modulus
& BitWise AND
**, Exponent
> Comparison
11. What is the output of the following code?
for i in range(10, 15, 1):
print( i, end=', ')
10, 11, 12, 13, 14,
10, 11, 12, 13, 14, 15,
12. What is the output of the following code?
listOne = [20, 40, 60, 80]
listTwo = [20, 40, 60, 80]
print(listOne == listTwo)
print(listOne is listTwo)
TRUE
TRUE
TRUE
FALSE
FALSE
TRUE
13. The ‘in’ operator is used to check if a value exists within an iterable object container such as a list. Evaluates to true if it finds a variable in the specified sequence and false otherwise.
TRUE
FALSE
14. What is the output of the following code?
str = "pynative"
print (str[1:3])
py
yn
pyn
yna
15. What is the output of the following code?
valueOne = 5 ** 2
valueTwo = 5 ** 3
print(valueOne)
print(valueTwo)
10
15
25
125
ERROR
