NEW
Font size
WorksheetsPython set 4
Total questions: 44
Worksheet time: 1hrs 6mins
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
How many times will 1 be printed
3
4
5
6
A while loop equivalent of the for loop above is
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
Match the following for the values each range( ) function will generate.
a-1, b-2, c-4, d-3, e-5
a-2, b-5, c-4, d-1, e-3
a-3, b-2, c-5, d-1, e-4
None
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
How many times the following loop will execute:
i = 1
while True:
print(i)
i += 2
0
2,4,6,8,..................
1,3,5,7,9,.............
1,2,4,6,8......................
for loop in python works on:
1.range
2.iteration
3.Both of the above
4.None of the above
i = 1
while True:
if i%7 == 0:
break
print(i)
i += 1
123456
1234567
error
none
i = 1
while False:
if i%2 == 0:
break
print(i)
i += 2
1
1357......
1234......
none of the mentioned
x = 123
for i in x:
print(i)
1 2 3
123
error
none of the above
for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")
01234 Here
012345 Here
01234
12345
string = "my name is x"
for i in string:
print (i, end=", ")
m, y, , n, a, m, e, , i, s, , x,
m, y, , n, a, m, e, , i, s, , x
my, name, is, x,
error
x = 'abcd'
for i in range(len(x)):
print(i.upper())
a b c d
0 1 2 3
error
1 2 3 4
x = 'abcd'
for i in range(len(x)):
x = 'a'
print(x)
a
abcd abcd abcd
a a a a
none
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'"")
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
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
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
You have the following dictionary definition:
d = {'foo': 100, 'bar': 200, 'baz': 300}
What method call will delete the entry whose value is 200?
delete d('bar')
d.pop("bar")
d.remove("bar")
None of the above
Which operator checks if a value is equal to another value?
+
=
==
!=
name = 'Dave'
print (name)
Which is the Python logo?
What is an input?
A command that allows us to ask the user to enter some data.
To plug in something.
Data displayed on a screen.
A function
What is an output?
A piece of data that is shown on the screen.
Data that the user enters
An output
A orange
x = 5
y = 6
print("x*y")
The code above displays the following:
11
x*y
Syntax Error
30
Choose the correct operators used in python:
divide, multiply, add, subtract
/, *, +, -
div, mul, +, -
\, x, +, -
~, *, +, -
Which operator checks if a value is not equal to another value?
==
+=
!=
=
A data type that can have one of two values: True or False
boolean
variable
modulo
interpreter
name = "Bob"
if name == "Bob":
print ("Hello " + name)
else:
print ("I dont know you")
Integers are ____________ and floats are _____________
whole numbers and exponents
powers and fractions
fractions and whole numbers
whole numbers and decimal numbers
