Worksheetschristmas holiday happy activity python 2023
Total questions: 74
Worksheet time: 4hrs 59mins
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!)
What is the output?
True
False
condition1
condition2
Given the nested if-else below, what will be the value x when the code is executed successfully.
0
4
2
3
This operator checks to see if one value is the same as the other value
==
!=
>
<
What would be outputted here?
Bigger than 2!
Number is 5
Bigger than 2!
Number is 5
Nothing
What will be outputted?
number is bigger than 10
nothing
an error
NUMBER IS BIGGER THAN 10
What is the output?
3
3
7
3
5
7
7
Which keyword is used to display output in Python?
output
input
display
Which keyword is used to take input from the user in Python?
read
scan
input
get
What is the syntax to check if two values are not equal in Python?
!==
!=
==
<>
What is the syntax to check if a value is greater than or equal to another value in Python?
>
>=
<
==
What is the syntax to check if a value is greater than another value in Python?
a < b
a > b
a >= b
a == b
Which logical operator is used to combine two conditions and returns True if both conditions are True?
and
xor
not
or
Which logical operator is used to combine two conditions and returns True if at least one condition is True?
xor
not
and
or
Which logical operator is used to negate a condition?
not
or
and
xor
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: ")
Put this code into the right order
age = int (input ("Enter age: "))
nextYear = age + 1
print ("Your age next year is: " + str(nextYear))
What is the first step to get started with Python?
Install Python
Learn Java
Learn C++
Buy a computer
Organize the following data into the correct data type
1
2
150
1025
1.0
1.2
0.0007
1810.0
2.0
500
"1"
'2.0'
'hello world'
"True"
'False'
True
False
What is the better way to create a variable for storing your name: (a) (b) (c)
What is the file extension for Python files?
.py
.java
.cpp
.html
What is the main purpose of using a 'for' loop in Python?
To iterate over a sequence of elements
To define a function
To create a class
To perform arithmetic operations
Which of the following is a valid way to comment in Python?
// This is a comment
# This is a comment
/* This is a comment */
%% This is a comment
Given: students = ["Jamie", "Ellie", "Jason", "Clara"]
What is the correct way to use the for loop?
for
students
in
students
:
What is the output of the following Python code?
print('Hello' + 'World')Hello World
HelloWorld
'Hello' + 'World'
TypeError
(a) are containers used to store data in Python.
To assign a value to a variable in Python, we use the (a) operator ( (b) ).
For example: x (c) 5 assigns the value 5 to the variable named "x".
This are the rules for naming variables in python:
-> Variable names must start with a letter or underscore.
-> Variable names can contain letters, numbers, and underscores.
-> Should not be a reserved keyword in Python.
What of the following names are invalid?
age
student_grade
name
score_1
totalMarks
isPassed
averageScore
2students
my name
variableName3
total_sales$
input
while
student-grade
Whitespace in Python is used to improve code (a) and organization.
To remove whitespace from a string in Python, we can use the (a) function. For example, " Hello ". (b) would remove the leading and trailing whitespace from the string and return "Hello".
In python, which value is an empty list?
{ }
" "
( )
[ ]
How would you assign the value 'hello' as the third value in a list stored in a variable named test? (Assume test contains [2, 4, 6, 8, 10].)
(a)
spam contains the list ['a', 'b', 'c', 'd']
What does spam[1] evaluate to?
'a'
'b'
'c'
'd'
spam contains the list ['a', 'b', 'c', 'd']
What does spam[3] evaluate to?
'a'
'b'
'c'
'd'
spam contains the list ['a', 'b', 'c', 'd']
What does spam[-1] evaluate to?
'a'
'b'
'c'
'd'
spam contains the list ['a', 'b', 'c', 'd']
What does spam[0] evaluate to?
(I fixed this question. Pick the actual true answer)
'a'
'b'
'c'
'd'
test contains the list ['banana', 3.14, True, 15]
What does test.index('banana') evaluate to?
(a)
test contains the list ['banana', 3.14, True, 15]
What does test.index(3.14) evaluate to?
(a)
test contains the list ['banana', 3.14, True, 15]
What does test.index(15) evaluate to?
(a)
test contains the list [3.14, 'cat', True, 'cat', 15]
What does len(test) evaluate to?
(a)
Match the following
This method will add values only at the end of a list
append( )
This method can add values anywhere in a list
insert( )
This method can remove a value from a list
remove( )
spam = ['cat', 'dog', 'moose']
spam.reverse()
What will be the new list?
(a)
Which data types can be sorted with the sort( ) method? Pick all correct answers
Integers
Strings
Booleans
Which of the following create an empty dictionary called person?
person = dict()
person = ()
person = []
person = {}
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
list
string
dictionart
dictionary
quiz = ("Do you help out at home? ":"yes" }
Which is the correct statement to delete a key-value pair from a dictionary called alien_11?
alien_11.delete()
alien_11.discard()
alien_11.remove()
del alien_11['keyName']
________________method will returns number of key-value pairs in the given dictionary.
len( )
pop( )
del( )
keys( )
values( )
How much information can a dictionary store in python?
Almost limitless amount of information.
Less than 1 Kilobyte.
A very limited amount of information.
A infinite amount, a dictionary can contain all the data in the world and more.
What is a string in Python?
A string is what shoes have so they don’t fall off your feet.
A string is the representation of numbers in Python.
A string is a collection of items of any data type.
A string is a series of characters.
What is it a dictionary in python?
It is a collection of key-value pairs.
It is the representation of numbers in Python.
It is a set of values associated with each other.
It is a series of characters.
What is it a key-value pair?
It is a collection of key-value pairs.
It is the representation of numbers in Python.
It is a set of values associated with each other.
It is a series of characters.
What type of data can it be a key value?
A key’s value can be a number, a string, a list, or even another dictionary.
A key’s value only can be a number.
A key’s value only can be a string.
A key’s value only can be a list.
How many key-value pairs does the following dictionary have?
alien_0 = {'color': 'green', 'points': 5, 'power': 50}
(a)
Can you add new key-value pairs to dictionaries?
Yes
No
Does python allow you to loop through a dictionary?
Yes
No
What method can we use to print all the key-value pairs of a dictionary as a list?
items()
keys()
values()
set()
What method can we use to loop through all the keys of a dictionary?
items()
keys()
values()
set()
What method can we use to loop through all the values of a dictionary?
items()
keys()
values()
set()
What function can you use to loop through all the values of a dictionary avoiding duplicated values?
items()
keys()
values()
set()
What is nesting in python?
It is a natural instinct experienced by many expecting mothers, most commonly in the last trimester.
Are dynamic structures, and you can add new key-value pairs
to a dictionary at any time.
It is to store multiple dictionaries in a list, or a list of
items as a value in a dictionary.
