NEW
Font size
WorksheetsPython Programming Quiz
Total questions: 50
Worksheet time: 25mins
What is the first step in problem-solving?
Coding the solution
Defining the problem
Testing the solution
Debugging the code
Which of the following is a correct way to start a Python program?
#include
BEGIN
print("Hello World")
echo "Hello"
Which of the following is a mutable data type?
Tuple
List
String
Int
What will type(3.14) return?
<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
Which operator is used for floor division?
/
//
%
**
Which function converts a string "100" to integer?
int("100")
str("100")
float("100")
bool("100")
Which of the following is a syntax error?
print("Hello)
x = 5 + 3
y = x * 2
name = "Alice"
Logical error is when:
Program does not run
Program runs but gives wrong output
Program throws syntax error
Program crashes
Which statement is used to get user input?
scan()
input()
read()
get()
Which is not a valid Python identifier?
my_var
var123
123var
_var
Example of conditional statement:
for
if
while
print()
What is 5 % 2?
0
1
2.5
5
Which is a logical operator?
+
and
*
=
Output of len("Python")?
5
6
7
8
String method to convert to uppercase?
upper()
lower()
capitalize()
title()
Remove whitespace from start & end of string?
strip()
replace()
split()
join()
"Hello".replace("H","J") returns:
"Hello"
"Jello"
"JelloHello"
"HelloJ"
Tuple method to count occurrences?
append()
count()
remove()
insert()
First element of t = (1,2,3)?
t[0]
t[1]
t.first()
t.get(0)
Dictionary method to get all keys?
keys()
append()
pop(3)
insert()
Add new key-value to dictionary d={}?
d.add("a",1)
d["a"]=1
d.append("a",1)
d.insert("a",1)
Loop to execute block fixed times?
while
for
if
elif
Loop continues while condition true?
for
while
do-while
repeat
list("Python") returns?
"Python"
['P','y','t','h','o','n']
['Python']
['Py','th','on']
Add 10 to l=[1,2,3]?
l.add(10)
l.append(10)
l.insert(10)
l.push(10)
Remove element at index from list?
pop()
remove()
delete()
discard()
Immutable type?
List
Tuple
Dictionary
Set
Check if key exists in dict?
key in dict
dict.has_key(key)
key.exists()
dict.contains(key)
Correct if-statement syntax?
if x = 5:
if x == 5:
if (x = 5)
if x := 5
Convert value to float?
float()
int()
str()
bool()
Output of: x = 5 if x > 3: print("Yes") else: print("No")
Yes
No
5
Error
Exponentiation operator in Python?
^
**
*
//
"Python"[1:4] returns?
Hel
yth
Pyt
hon
"Python".split("y") returns?
['Python']
['P','thon']
['Py','th','on']
['P','y','t','h','o','n']
" ".join(['Hello','World']) returns?
'HelloWorld'
'Hello World'
'H e l l o W o r l d'
'Hello+World'
Remove value x from list?
l.pop(x)
l.remove(x)
l.del(x)
l.discard(x)
Add element at index 1 in list?
l.add(1,10)
l.insert(1,10)
l.append(10,1)
l.push(1,10)
Remove last element in dictionary d?
d.popitem()
d.pop()
d.remove()
d.clear()
Returns value of key k safely?
d.get(k)
d[k]
d.lookup(k)
d.search(k)
Iterate dictionary keys?
for k,v in d:
for k in d:
for d in k:
for v in d:
What is bool("")?
True
False
Error
None
Output of 5==5 and 3>2?
True
False
Error
None
Output of not(5>2)?
True
False
3
Error
Iterates over list [1,2,3]?
for x in [1,2,3]: print(x)
while x in [1,2,3]: print(x)
do x in [1,2,3]: print(x)
loop x in [1,2,3]: print(x)
t = (1,2,3); t[1] = 5 gives?
(1,5,3)
Error
(5,2,3)
(1,2,3,5)
Tuple with one element?
(5)
(5,)
[5]
{5}
Delete key 'a' from dictionary d={'a':1}?
del d['a']
d.remove('a')
d.popitem('a')
d.pop('b')
Check if list l=[1,2] contains 2?
2 in l
2.exists(l)
l.has(2)
l.check(2)
Convert integer 5 to string?
str(5)
int(5)
float(5)
bool(5)
Which is true about Python dictionaries?
Keys are mutable
Values are immutable
Keys are unique
Dictionaries are ordered in Python 2
