Font size
WorksheetsPython basics
Total questions: 67
Worksheet time: 32mins
Select all strings:
greeting = (Hello)
greeting = ("Please enter your name")
greeting = (Welcome to Comp Sci)
greeting = ("Happy Friday!!!")
Please select all floating point numbers:
1.444
34567
777.980
32.0
21
What is the default data type in Python?
Real
String
Integer
Number
What is the Python code needed to display a word on the screen?
print"hello"
"hello"
print("hello")
print="hello"
What is the Python code needed to ask a user for input?
input("what is your name?")
input="what is your name?"
(input)=what is your name?
input=what is your name?
Which is the correct way to store an input as a variable in Python?
answer("what is your name?")
input = "answer"(what is your name?)
answer = input("what is your name?")
input=(what is your name?)
Which character represents a comment in Python code?
*
#
&
$
Which of the following data types can consist of numbers, alphabets and symbols?
String
Integer
Float
Boolean
Which of the following data types is the most appropriate for 23 June 2020?
Float
Boolean
Integer
String
78.0
String
Integer
Float
Number
"89 / 90"
String
Integer
Float
Number
56 + 30
String
Integer
Float
Number
"89"
String
Integer
Float
Number
What is a String?
A data type that contains whole numbers. eg: 3, 45, 124
Numbers with decimal point. eg: 0.5, 2.45, 56.04
Group of characters between quotation marks. eg: "dog"
Data type that can only be True or False.
What is an Integer?
A data type that contains whole numbers. eg: 3, 45, 124
Numbers with decimal point. eg: 0.5, 2.45, 56.04
Group of characters between quotation marks. eg: "dog"
Data type that can only be True or False.
Which value is an Integer?
64
"cat"
True
0.5
Which of the following are true of Python lists?
A list may contain any type of object except another list
A given object may appear in a list more than once
All elements in a list must be of the same type
These represent the same list:
['a', 'b', 'c']
['c', 'a', 'b']
There is no conceptual limit to the size of a list
Assume the following list definition:
>>> a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']
Several short REPL sessions are shown below. Which display correct output?
>>> print(a[-6])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> a[:] is a
True
>>> print(a[4::-2])
['quux', 'baz', 'foo']
>>> print(a[-5:-3])
['bar', 'baz']
>>> max(a[2:4] + ['grault'])
'qux'
List a is defined as follows:
a = [1, 2, 3, 4, 5]
Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:
a[2] = []
a[2:2] = []
a[2:3] = []
del a[2]
a.remove(3)
Consider the following nested list definition:
x = [10, [3.141, 20, [30, 'baz', 2.718]], 'foo']
A schematic for this list is shown above:
What is the expression that returns the 'z' in 'baz'?
x[1][2][1]
x[1][2][1][2]
x[1][2][2]
x[1][1][2]
List a is defined as follows:
a = [1, 2, 3, 4, 5]
Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:
a[2:3] = []
a[2] = []
a.remove(3)
a[2:2] = []
del a[2]
List a is defined as follows:
a = ['a', 'b', 'c']
Which of the following statements adds 'd' and 'e' to the end of a, so that it then equals ['a', 'b', 'c', 'd', 'e']:
a += ['d', 'e']
a[-1:] = ['d', 'e']
a += 'de'
a.append(['d', 'e'])
a[len(a):] = ['d', 'e']
You have a list a defined as follows:
a = [1, 2, 7, 8]
Write a Python statement using slice assignment that will fill in the missing values so that a equals [1, 2, 3, 4, 5, 6, 7, 8].
a[2:2] = [3, 4, 5, 6]
a[1:2] = [3, 4, 5, 6]
a[2:3] = [3, 4, 5, 6]
a[3:5] = [3, 4, 5, 6]
Suppose you have the following tuple definition:
t = ('foo', 'bar', 'baz')
Which of the following statements replaces the second element ('bar') with the string 'qux':
t[1] = 'qux'
t(1) = 'qux'
t[1:1] = 'qux'
It’s a trick question—tuples can’t be modified.
Write Python code to create a tuple with a single element, the string 'foo', and assign it to a variable called t.
(a)
Consider this assignment statement:
a, b, c = (1, 2, 3, 4, 5, 6, 7, 8, 9)[1::3]
Following execution of this statement, what is the value of b:
5
4
3
6
7
Assume x and y are assigned as follows:
x = 5
y = -5
What is the effect of this statement:
x, y = (y, x)[::-1]
The values of x and y are swapped
The values of x and y are unchanged
Both x and y are -5
Both x and y are 5
What are the three main programming structures?
Sequence, selection, iteration
Structured, object-oriented, procedural
Java, Python, Visual Basic
Machine, assembly, high-level
Yes
In a Python program , a control structure:
directs the order of execution of the statements in the program
dictates what happens before te program starts and after it terminates
defines program-specific data structures
manages the input and output of control characters
What is the output of the above program ?
Am I here?
Or here ?
Am I here ? Or here ?
Or here ? Or over here ?
If the user inputs : 2<Enter> , what does the following code snippet print ?
Yes
No
May be
Nothing printed
Error
Function range(3) is equivalent to "
range(1,3)
range(0,3)
range(0,3,1)
range(1,3,0)
What is the output?
condition
True
Program has a syntax error.
3 > 2
What is the output?
more than 7
more than 23
spam
7
What is the output?
3
3
7
3
5
7
7
What is the output?
True
NIL
True
NIL
True
NIL
NIL
What is the output?
level 3
level 3
level 1
level 3
level 1
NIL
level 3
level 2
level 1
NIL
An If statement can be executed multiple times
FALSE
TRUE
The ‘else’ statement is optional in Python
TRUE
FALSE
It is possible to execute both the statements under if and else at the same time.
TRUE
FALSE
There can be an else statement without an if statement
FALSE
TRUE
The program generates an error message if the "else" statement is not defined
FALSE
TRUE
Python supports (a) types of loops
What is the output?
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
What is the output if the user types "Python"?
Which symbol is used to indicate comments in Python?
//
#
/
<!--
What is the correct way to define a variable in Python?
variable_name = value
variable_name <- value
value = variable_name
variable_name : value
In Python, variables are:
Declared with a specific data type
Implicitly typed
Declared using the 'var' keyword
Only allowed in functions
Which of the following is NOT a valid variable name in Python?
_myVar
123_var
My-Var
myVar2
What will be the output of this code?
5
10
15
The code will raise an error
What is the data type of the variable in this code?
int
float
str
bool
What is the output of this code?
Greater than 5
Less than or equal to 5
10
The code will raise an error
What is the output of this code?
5
10
15
The code will raise an error
What is Python?
A high-level programming language
low-level programming language
A markup language
A database management system
What is the purpose of indentation in Python?
To make the code look neat and organized
To separate code blocks
To improve the program's performance
To add spaces between characters
Which of the following is not a built-in data type in Python?
int
float
decimal
str
Which data type is used to represent non-integer numeric values in Python?
int
float
str
bool
Which data type is used to represent true or false values in Python?
int
float
bool
str
What is the output of this code snippet?
510
TypeError
15
"510"
What is the output of this expression?
True
False
Error
None
Which operator is used for exponentiation in Python?
^
**
&
//
Which operator is used for floor division in Python?
/
//
%
*
Which operator is used to check for the inequality of two values in Python?
>
<
==
!=
What is the result of this expression?
"Hello World"
"HelloWorld"
Error
None
What is the result of this expression?
3.3333333333333335
3.0
3
4.0
