Font size
WorksheetsPython Basic Exam #1
Total questions: 81
Worksheet time: 1hrs 1mins
Empty curly braces in an assignment statement will create which type of data structure?
(s = {})
List
Dictionary
Stack
Set
Which is not true about sets?
The .pop() method removes elements
They are unordered
Each element is unique
Which data structure stores key/value pairs?
Sets
Stacks
Lists
Dictionaries
Each key/value pair in a dictionary is separated by this symbol:
/
,
:
;
Which data structure is exponentially more efficient than the others?
List
Set
Tuple
Hash Map
Choose all of the following which are built in data types in Python
dict
list
set
tuple
A dictionary is an example of a sequence ...
True
False
Which code segment when inserted in the blank sets the "Year" from 2006 to 2008?
birthday = {
"Month": "January",
"Day": "01",
"Year":2006
}
__________________________________
OUTPUT: 2008
birthday["Year"]=2008
birthday[Year]=2008
birthday [2008]
birthday[2006]=2008
What will this code do?
birthday = {
"Month": "January",
"Day": "01",
"Year":2006
}
for x in birthday:
print(x)
Prints all the key names in the dictionary
print all the key and value pairs is the dictionary
The dictionary dnry is initialized as follows:
dnry = {"L": 8, "W": 5, "H": 11}
Which statement would evaluate to 5?
dnry[1]
dnry["W"]
dnry["5"]
dnry[2]
Score = Score + 1
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
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
Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.
while loop
for loop
nested loop
infinite loop
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
while loop
for loop
nested loop
infinite loop
What does the code print?
10
7
4
1
Done
10
9
8
7
6
5
4
3
2
1
Done
Done
10
7
4
1
-2
-5
... and more, running infinitely.
An example of Python code that creates a variable and assigns it to the string "Hello!"
goodbye = "HAVE A GREAT DAY!"print(goodbye)
welcome = "Hello!"
"Today I had \"pizza"\ for lunch"
print("Hello!" * 3)
A: Strings can be changed during execution
B. Strings can be enclosed within single, double or even triple quotes
C. Strings are immutable
A,B & C are True
A,B are True but C is False
B, C are True but A is False
A,C are True but B is False
+ operator represents print(3*'hi')
3hi
3*hi
hihihi
Error
print('e' in 'silence')
1
2
True
False
What is the output of the following code?
5
Error
2
1
" "
String
Integer
Float
Number
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
For tuples and list which is correct?
List and tuples both are mutable.
List is mutable whereas tuples are immutable.
List and tuples both are immutable.
List is immutable whereas tuples are mutable
Which is a correctly declared tuple?
a = ("orange", "yellow", "red")
a = "orange", "yellow", "red"
a = ["orange", "yellow", "red"]
a = "orangeyellowred"
Can you have an empty tuple z = () or an empty string w = []?
yes
no
If L1=[2,4,8,16], L2=[32,64] what is L1+L2
[2,4,8,16,32,64]
[2,4,8,16][32,64]
[2,4,8,16],[32,64]
None of the above
Suppose list1 is [1, 3, 2], What is list1 * 2 ?
[2, 6, 4].
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
Unable to change.
Immutable
A particular way of organizing data in our programs.
Data Structure
A heterogenous, immutable data type that stores an ordered sequence of things.
Tuple
A heterogenous, mutable data type that stores an ordered sequence of things.
List
Add a particular item to the end of a list.
append()
Pieces of code that only run "under certain conditions":
conditional statements
control flow statments
syntax
variables
If you want to test more than one condition (chained condition), what do you use after if statement?
elif
else
ifif
else if
‘If’ is a decision making statement
TRUE
FALSE
Which of the following conditions tell me to sleep if my alarm did not go off (alarm = False) and I’m tired (tired = True)?
Both alarm and tired default assignment is True.
How can you check if a value is NOT equal to a specific value in Python's if statement?
Use the != operator
Use the == operator
Use the <> operator
Use the <= operator
What will print when this program is executed?
You need an umbrella.
You do not need an umbrella.
True
False
Nothing will print
What symbol is used in python to assign values to a variable?
:
*
=
==
What is the correct name for this symbol?
==
Assignment
Equal to
Greater than
Less than
x = 10
y = 10
print(x != y)
True
False
x = 5
y = 3
print(x == y)
True
False
What is this symbol called? (*)
star
asterisk
apostrophe
multiplication
The result of 10%2 will be :
1
5
2
0
Click all comparison operators
!=
*=
==
>=
=
Click all arithmetic operators
**
=
+=
-
%
An expression is
A set of steps for performing a task, like a recipe.
An ordered list of values or objects.
To combine two strings of text into a single string.
Any valid set of values, variables, operators, and functions that produces a value or result.
Can you add 2.6 to "Cat"?
Yes! I'll demonstrate on the board!
No. You're probably nuts for thinking this.
Please select all floating point numbers:
1.444
34567
777.980
32.0
21
What data type would store the value: True
Boolean
String
Integer
Float
"89 / 90"
String
Integer
Float
Number
What is the data type of ["Sunday","Monday","Tuesday"]
List
String
Numeric
Tuple
Which of the following correctly stores 'price' as a decimal number?
price = int ( input ("Price: ")
price = str( input ("Price: ")
price = float ( input ("Price: ")
price = input ("Price: ")
Which is the correct way to declare 3 variables, 'a' , 'b', 'c' to 1?
a = b = c = 1
a,b,c = 1
a == b
b == c
c == 1
abc = 1
Order the below into the correct order for an assignment statement in Python. Not all options are used.
(a) (b) (c)
How do you declare and initialize a variable with the integer data type in Python?
(a)
Which of the following data types can consist of numbers, alphabets and symbols?
String
Integer
Float
Boolean
What will be the output from the following Python code?
print("3+4")
7
3+4
34
SyntaxError
What data value would store the value: -9?
Float
Integer
String
Boolean
What is programming, and why is it important for students to learn about it in today's world?
a) Programming is a type of video game.
b) Programming is the process of instructing a computer to perform tasks, and it's important for students to learn because it empowers them to solve problems and automate tasks.
c) Programming is a form of storytelling.
d) Programming is only relevant to professional software developers.
How would you explain the basic syntax of Python to a beginner, and why is Python often recommended as a first programming language for students?
a) Python is recommended for students because it has a complex syntax.
b) Python's syntax is difficult for beginners to grasp.
c) Python is recommended for its simple and readable syntax, making it accessible for beginners.
d) Python is recommended because it's the only language available for students.
What are some common use cases for input/output functions in Python, and how can students effectively use these functions to interact with their programs?
a) Input/output functions are only used by professional programmers.
b) Input/output functions in Python are used for making coffee.
c) Input/output functions are used to read and write data to/from files, and to interact with users through the command line or graphical user interfaces.
d) Input/output functions in Python are used for gaming purposes only.
=
+
*
%
What is a input?
A function that allows us to ask the user to enter some data.
To plug in something.
Data displayed on a screen.
A function
name = 'Dave'
print (name)
What is the proper syntax for Python comments?
<!-- Python comment -->
<comment> Python comment <comment>
# Python Comment
/* Python Comment */
