Font size
WorksheetsPython Quiz
Total questions: 79
Worksheet time: 53mins
is integer a number
true
false
chose which is a floating point
14
15.5
chose a string
"tim"
"tim
'tim'
"tim
tim
in python does it matter if we type ' and " together
true
false
in python does i t matter if we right "and" this together and 'and' together
true
false
is boolean a data type or a condition
data type only
data type and condition only
condition only
where is python used
web aplications
data science
mobile apps
GUI applications
is boolean true or false
true only
false only
true and false only
Who developed Python Programming Language?
a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom
Which of the following is the correct extension of the Python file?
a) .python
b) .pl
c) .py
d) .p
What will be the value of the following Python expression?
4 + 3 % 5
a) 7
b) 2
c) 4
d) 1
Which of the following is used to define a block of code in Python language?
a) Indentation
b) Key
c) Brackets
d) All of the mentioned
Which of the following character is used to give single-line comments in Python?
a) //
b) #
c) !
d) /*
What is the order of precedence in python?
a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Which of the following functions is a built-in function in python?
a) factorial()
b) print()
c) seed()
d) sqrt()
Which of the following is not a core data type in Python programming?
a) Tuples
b) Lists
c) Class
d) Dictionary
To add a new element to a list we use which Python command?
a) list1.addEnd(5)
b) list1.addLast(5)
c) list1.append(5)
d) list1.add(5)
What will be the output of the following Python statement?
>>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc
What will be the output of the following Python code?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]
a) olleh
b) hello
c) h
d) o
What will be the output of the following Python code?
>>>str1="helloworld"
>>>str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld
What will be the output of the “hello” +1+2+3?
a) hello123
b) hello
c) Error
d) hello6
Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
a) 5
b) 4
c) None
d) Error
Suppose list1 is [2445,133,12454,123], what is max(list1)?
a) 2445
b) 133
c) 12454
d) 123
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
a) [2, 33, 222, 14]
b) Error
c) 25
d) [25, 14, 222, 33, 2]
If a=(1,2,3,4), a[1:-1] is _________
a) Error, tuple slicing doesn’t exist
b) [2,3]
c) (2,3,4)
d) (2,3)
Which of the following statements create a dictionary?
a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
d) All of the mentioned
What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
d["john"]
a) 40
b) 45
c) “john”
d) “peter”
What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b)
print(a)
a) {1: ‘A’, 2: ‘B’, 3: ‘C’}
b) Method update() doesn’t exist for dictionaries
c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
d) {4: ‘D’, 5: ‘E’}
Python accepts single ('), double (") and triple (''' or """) quotes to denote strings. Which of the following is NOT acceptable Python syntax?
print('Hello World')
print("Hello World")
print('Hello World")
print(""'Hello World'"")
What is printed by the following statement?
print("P" not in "APCSP")
True
False
Error
What is printed by the following statement?
print("A" in "APCSP")
True
False
Error
Evaluate the following expression:
"dog" < "Dog"
They are the same word
True
False
For strings, the + operator represents
Concatenation
Addition
Appending
Recantation
data = "No Way!" The expression len(data) evaluates to:
7
9
8
6
Which operator returns True if target string is somewhere in the search string; otherwise it returns False.
==
!=
in
is
What syntax can you use to insert a line break between strings so that they appear over multiple lines?
\l
/
\\n
\n
Which is the most appropriate data type for: "13th December"
Float
Boolean
Integer
String
What will the output be from the following code?
print("Hello world!" * 2)
TypeError
Hello world world!
Hello world!Hello world!
Hello world! * 2
What will the output be from the following code?
print("Hello world!\nHello world!")
Hello world! Hello world!
Hello world!
Hello world!
SyntaxError
Hello world!
What will the output be from the following code?
print("3+4")
7
34
3+4
SyntaxError
print("12"*3)
What would this print?
121212
36
24
12*3
What will the output be from the following code?
print("Hello world!")
SyntaxError
Hello world!
"Hello world!"
print(Hello world!)
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
The equivalent of the above for loop using the while syntax would be
The above program prints
Numbers 1 to 10 in reverse order
Numbers 1 to 11 in reverse order
Numbers 1 to 10
Numbers 1 to 11
The program above prints
Numbers between 1 and 100 that are multiples of 5
Numbers between 1 and 100
Numbers between 1 and 100 divisible by 5
Numbers between 1 and 101 that are multiples of 5
The code above prints all numbers between 1 and 30 that are
not divisible by 5
divisible by 5
The program above prints the sum of
all odd numbers less than 100
all even numbers less than 100
all numbers less than 100
The program above prints the sum of all the numbers between 0 and 101 that are
alternate odd numbers
alternate even numbers
alternate numbers
The program above prints each number between 1 and 10
as many times as the number itself
10 times
11 times
The program above prints each number between 1 and 10
as many times as the number itself
10 times
11 times
How many times will 1 be printed
3
4
5
6
for i in 100 :
print ( i )
Syntax error
prints numbers 0 to 100
prints numbers 1 to 100
prints numbers 0 to 99
prints numbers 1 to 99
What is the output of the program above
10
15
18
17
16
A while loop equivalent of the for loop above is
What is the value of the variable sum after the code above executes
54
44
64
34
74
What does this program print
2 + 2 = 4
4 + 4 = 8
8 + 8 = 16
16 + 16 = 32
32 + 32 = 64
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 4 = 6
2 + 6 = 8
2 + 8 = 10
2 + 10 = 12
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 2 = 4
2 + 4 = 6
2 + 6 = 8
2 + 8 = 10
__________ keyword is used for creating a function in Python.
define
fun
def
function
What is the output of the given code?
10 20 10
10
20
10 20
What is the output of the given code?
10 20 10 20
10 20 10
10 20 20
Error
Python supports variable number of parameters.
True
False
Function header in Python contains _________________.
function name
list of parameters
return type
all the above
Only A & B
The default return value of any function in Python is _______________.
null
0
None
Garbage value
__________ is the built-in function to know the type of a variable or function.
id()
type()
data_type()
none of the above
___________ are the arguments passed to a function in correct positional order.
Keyword arguments
Default arguments
Variable-length arguments
Required arguments
none of the above
times is ________________ type of argument.
default arguments
keyword arguments
positional arguments
arbitrary positional arguments
arbitrary keyword arguments
Select the advantages of functions
Modular programming
Code re-usability
Improving clarity of the code
All the above
Which python operator means 'less than or equal to'?
>=
>
<
<=
What is the value of the expression 100 / 25?
4
4.0
"4.0"
'4.0'
What is the output of the following code :
print 9//2
4.5
4.0
4
3
Which one of these is floor division?
/
//
%
None of the mentioned
What is the answer of this expression, 22 % 3 is?
7
1
0
5
x = 4.5
y = 2
print(x//y)
2.0
2
9
9.0
x = 5
print(x > 3 and x < 10)
True
False
x = 8
print(x > 3 or x < 20)
True
False
x = 5
y = 3
print(x == y)
True
False
x = 10
y = 10
print(x != y)
True
False
x = 5
x%=3
print(x)
2
2.0
3
3.0
print(not (0<1))
TRUE
FALSE
TYPE ERROR
