Font size
WorksheetsPython 101 Quiz - 101 Questions
Total questions: 101
Worksheet time: 51mins
What will this code result to?
print(len("🤚"))
Syntax error
1
2
3
Solve this python code and choose the correct answer.
print(len("👩👩👦👦")
Syntax error
1
4
7
How can you insert comments in python?
/*This is a comment*/
'''This is a comment'''
#This is a comment
//This is a comment
Which of these is an incorrect python syntax for variables?
myvar
_myvar
MyVar
my-var
How do you create a variable with numeric value 5987658765 in python?
a = 5987658765
x = int(5987658765)
Is is not possible to create a variable of such a large value in python
none of these
Python files should always have the following extension
.python
.txt
.py
.pytn
How do you create a floating-point variable with value 5.9?
x = 5.9
y = float(5.9)
a = 5 + 0.9
b = 6 - 0.1
Choose the correct syntax for showing the type of variable or object?
print(typeof(a))
print(type(a))
print(typeOf(a))
print(typeof_a)
Choose the right syntax for creating a function
def my_function():
create myfunction():
name myfunction():
none of these
In python, which of these will print Hey There
"Hey There"
'Hey There'
'''Hey There'''
None of the above
Write the correct syntax for getting the first letter of the string
x = slice("Hello", 0,1)
x = sub("hello", 0)
x = "Hello"[0]
x = snip("Hello",0)
Which of these inbuilt python function helps remove whitespace at both ends of a string?
remove()
trip()
strip()
rem()
Which method will help you change all the string values to upper case?
UpperCase()
UC()
upper()
upperCase()
------- method helps you replace the parts of a string
replace()
repl()
switch()
replaceString()
Which of these operators helps you get the floor division in python?
_
/
//
%
If a = 50//3, then print(a) would output?
125000
16.666666
16
17
If a = 50 % 25, what would print(a) result to?
0
1
2
1.0
Which operator helps you compare two values?
<>
=
==
><
Which of these is a LIST in python?
("apple", "banana", "orange")
["apple", "banana", "orange"]
{"apple", "banana", "orange"}
{1:"apple", 2:"banana", 3:"orange"}
Which of these is a TUPLE in python?
("apple", "banana", "orange")
["apple", "banana", "orange"]
{"apple", "banana", "orange"}
{1:"apple", 2:"banana", 3:"orange"}
Which of these is a DICTIONARY in python?
("apple", "banana", "orange")
["apple", "banana", "orange"]
{"apple", "banana", "orange"}
{1:"apple", 2:"banana", 3:"orange"}
Which of these is a SET in python?
("apple", "banana", "orange")
["apple", "banana", "orange"]
{"apple", "banana", "orange"}
{1:"apple", 2:"banana", 3:"orange"}
Which of these collections in python is ordered, changeable and also allows duplicate values?
tuple
list
dictionary
set
Which of these python collections does not allow duplicate values?
tuple
list
set
dictionary
What is the correct syntax for writing an if condition in python?
if x > y
if x > y:
if x > y then:
if x is greater than y:
Choose the correct syntax for writing a for loop in python
for every x in y:
for each x in y:
for x in y:
for all x in y:
Which of the following statements is used to exit a loop in python?
stop
exit
return
break
Add the missing part of the code to output
____("Hello World")
output
run
type
___is a comment.
Fill in the blank to make it a comment.
??
//
@
#
Fill in the blanks to make a variable named carname with the value Volvo
---- = '----'
'carname', Volvo
carname, "Volvo"
carname, Volvo
"carname", "Volvo"
Fill in the blanks to make a variable named x with the value 100
---- = ----
x, 100
x, "100"
"x", "100"
none
Display the sum of 5+10 using two variables a and b. Choose the values to fill in the blanks
a, 5, -
b, 10, +
a, 5, +
b, 10, -
Remove the unnecesary character/s in the variable name
2my-firstname = 'Python'
2,m
2,m,y
2,-
-
Add the correct syntax to the blank spaces to assign same value to all the variables
a___b___c= 'Python'
,
+
=
.
What would be the anwer to the following code?
x = 10
print(type(x))
str
float
int
lst
What would be the anwer to the following code?
x = "Hey There"
print(type(x))
str
float
int
lst
What would be the anwer to the following code?
x = 9.8
print(type(x))
str
float
int
flt
What would be the anwer to the following code?
x = ("apple", "banana", "cherry")
print(type(x))
tuple
str
list
set
What would be the anwer to the following code?
x = {"name" : "John", "age" : 36}
print(type(x))
tuple
dict
list
set
What would be the anwer to the following code?
x = True
print(type(x))
True
boolean
False
bool
Add the correct syntax to change it into a floating point number
a = 500
a = ____(a)
flt
floater
float
int
Add the correct syntax to change it into an integer
a = 500.00
a = ____(a)
flt
floater
float
int
Add the correct syntax to change it into a complex number
a = 500.00
a = ____(a)
cmp
complex
comp
c
Which method allows you to find the length of a string?
length
len
string
trim
Choose the syntax to slice the first character of the string.
txt = "Hey There"
slice=_____
slice.txt
trim.txt
txt[0]
snip(txt)
Choose the syntax to slice the characters from index position 2 to 4 of the string.
txt = "Hey There"
slice=_____
txt[2]
txt[2:4]
txt[2:5]
txt[:5]
Fill the code in the blank area to remove any whitespace from the start and end of the string.
txt = " Hello World "
x =
trim.txt
strip.txt
txt.strip()
txt.trim()
Change the value in txt to lower case
x = "Hey There"
x = ______
LowerCase(txt)
txt.lower()
txt.lowercase()
lower(txt)
Change the value in txt to upper case
x = "Hey There"
x = ______
UpperCase(txt)
txt.upper()
txt.uppercase()
upper(txt)
Replace the character I with Y
txt = "Patrick loves fish"
txt = _____
txt.rep("I", "Y")
txt.replace("I","Y")
replace.txt(I,Y)
rep.txt(I,Y)
Insert the correc syntax to add a placeholder for the age parameter
age = 36
txt = "My name is John, and I am ____ "
print(txt.format(age))
[]
{}
()
<>
What would the following statement print
print(10>9)
10>9
10 is greater than 9
True
False
What would the following statement print
print(10==9 and len("hey"==3))
True
Not True
Not False
False
What would the following statement print
print(10!=9 or len("hey"==5))
True
Not True
Not False
False
What would the following statement print
print(bool("abcdef"))
True
Not True
Not False
False
What would the following statement print
print(bool(0))
True
Not True
Not False
False
fruits = ["apples", "bananas", "oranges"]
if "apples" ___ fruits:
Choose the correct operator to fill in the blank
is there
in there
part of
in
Change the value of the first fruit in the fruit list to kiwi
fruits = ["apple", "banana", "cherry"]
___ = ___
fruits=fruits[1]
fruits[0]="kiwi"
fruits[1]="kiwi"
kiwi=fruits[0]
Specify which is the correct code to add orange to the fruit list
fruits = ["apple", "banana", "cherry"]
________
fruits.append(orange)
fruit.add(orange)
fruits.append('orange')
fruit.add('orange')
Specify which is the correct code to insert orange to the fruit list as the second item
fruits.insert(1,"orange")
fruits.insert(1,orange)
fruits.append('orange')
fruit.add('orange')
Specify which is the correct code to remove cherry to the fruit list as the second item
fruits = ["apple", "banana", "cherry"]
fruits.remove("cherry")
fruits.remove(cherry)
fruits.del(cherry)
fruit.add('orange')
Print the last item on this list using negative index
fruits = ["apple", "banana", "cherry"]
print(fruits[1])
print(fruits[-1])
print(fruits[0])
print(fruits[-2])
fruits = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
Choose the correct syntax to print all the fruits from banana to kiwi
print(fruits)
print(fruits[0,2,4]
print(fruits[1:5])
fruits = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
Choose the correct syntax to print number of items in this list
print(fruits)
print(len(fruits)
print(len(fruits))
none
Choose the correct option to print the first item in this tuple
fruits = ("apple", "banana", "cherry")
print(fruits(1))
print(fruits(0))
print(fruits[1])
print(fruits(01))
Choose the correct option to print the number of items in this tuple
fruits = ("apple", "banana", "cherry")
print(len[fruits])
print(fruits(len))
print(length(fruits))
print(len(fruits))
Print the last value in the tuple below using negative indexing
fruits = ("apple", "banana", "cherry")
print(fruits[2])
print(fruits[0])
print(fruits[1])
print(fruits[-1])
For the set below, how can you add another item orange to it.
fruits = {"apple", "banana", "cherry"}
fruits.add{"orange"}
fruits.add("orange")
fruits.add["orange"]
none
Use the correct method to add more than one items(more_fruits) to the set
fruits = {"apple", "banana", "cherry"}
more_fruits = ["orange", "mango", "grapes"]
fruits.add(more_fruits)
fruits.update(more_fruits)
fruits.increase(more_fruits)
fruits.append(more_fruits)
Use the correct method to remove banana from the set
fruits = {"apple", "banana", "cherry"}
fruits.remove("banana")
fruits.discard("banana")
fruits.increase(more_fruits)
fruits.append(more_fruits)
For the dictionary, print the model of the car using the get method
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
For the dictionary, change the value of year to 2022
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
year=2022
car(year)=2022
car["year"]=2022
car.year=2022
Add the key/value pair "color" : "red" to the car dictionary.
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
car['color']:'red'
car['color']='red'
car('color')='red'
car["color"]="red"
Use the pop method to remove the model from the dictionary
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
car.pop('model')
car.rem('model')
car.pop("model")
car.pop['model']
Which method will help you clear this dictionary
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
car.clear()
car.rem()
car.pop()
car.remove()
Print "Hello World" if a is greater than b.
a = 50
b = 10
___a___b___
print("Hello World")
Fill in the empty values
if, <=, :
if, <, :
if, >=, ;
if, >, :
Print "Hello World" if a is equal to b, else print "No"
Fill in the empty values
if, ==, :, else
if, >=, :, else
if, >=, ;, else
if, >, :, else
What does this code do
prints all the numbers from 1 to 6 in a column
prints all the numbers from 1 to 5 in a column
prints all the numbers from 1 to 5 in a row
prints all the numbers from 1 to 6 in a row
What does this code result in?
prints all the values from 1 to 6
prints all the values from 1 to 3
breaks the code
prints all the values from 1 to 4
What would happen when you run this code?
print the numbers 1,2,3,4,5
print numbers 1,2,3,4,5,6
print numbers from 1,2,4,5,6
print numbers 1,3,4,5
Python correct naming convention for variables is?
new_user25
NewUser25
25_new_user
25NewUser
NEWUSER25
If you want to create an empty list called colours in Python, which of the following is correct?
colours = [ ]
colours = ( )
colours = { }
colours = <>
print("12"*3) What would this print?
print("12"*3) What would this print?
What will the output be from the following Python code?
print(9/3)
3
3.0
9/3
SyntaxError
Which commands might be correct?
random. random(1, 10)
print(random.random( ))
print(random. randint(1,10))
import.random(2.7)
How do you define(assign) variables?
var="String"
func==Hello
var : 123
word= Hello
Which one does take you to next line?
\t
\n
/n
\\
Which of the following sequences would be generated by the given line of code?
range (10, 0, -5)
10,9,8,7,6,5
10, 5
0, 5, 10
10, 5, 0
In a Python program, what would be the increment value for the looping variable in the FOR LOOP code?
for x in range (25, 10, -5)
10
-5
25
5
Which of the following is a data type in Python?
int
words
string
decimals
x = 23
y = 3
print(x // y)
7
7.6666
7.7
Error
What is the output of the code shown in the image?
2
3
'2'
'3'
What is the output of the code shown in the image?
#
#
#
#
####
#
##
###
####
#
##
###
####
#####
