WorksheetsIG1 U2L1-L5 Python
Total questions: 108
Worksheet time: 56mins
What will be the output?
name = "Dave"
print (name)
Dave
'Dave'
name
(name)
It displays an output
What is the output from the following code?
print ("hello world")
What is the Python built-in function used to display numbers and text on the screen?
input
output
command
The punctuation requirements for printing a string in Python are:
( ) , ! and " "
( ) and !
( ) and " "
" " and !
What will be the output?
name = "Dave"
print ("name")
Dave
"Dave"
name
"name"
What is the name of the variable in this program?
colour
input
" "
What will this code print?
access denied
access granted
error
password
If the user enters 60, what is the output?
You are old!
You are middle-aged!
You are young!
Error message
if age is less than 20 then
What symbol must you place at the end of an if statement?
)
:
;
}
What is an indentation in Python?
A line of code that returns a value
A subroutine
A block of code that creates a variable
A code block (body of a function, loop etc.) starts with indentation and ends with the first unintended line.
1==0
True
False
What will this code display?
a = 6
if a => 6:
print("pass")
else:
print("fail")
pass
fail
nothing because there will be an error
passfail
what does != mean
not
swap value
not equal
equal
What will this code print?
access denied
access granted
error
password
What will happen when this program is run?
Syntax error
One will be displayed
Zero will be displayed
One then Zero will be displayed
What will this code print?
access denied
access granted
error
password
The selection statements are used to select a part of the program to be executed based on a condition.
True
False
In Python, we use the if statement to test a condition and decide the execution of a block of statements based on that condition result.
True
False
In Python, When we want to test multiple conditions we use elif statement.
True
False
If it is True, then the block of statements is executed and if it is False, then the block of statements is ignored.
if statement
if-else statement
if-elif statement
If the condition is True, then the true block of statements is executed and if it is False, then the false block of statements is executed.
if statement
if-else statement
if-elif statement
Which selection execution flow is given:
if statement
if-else statement
if-elif statement
Which selection execution flow is given:
if statement
if-else statement
if-elif statement
4
3
2
1
3
2
1
0
4
3
2
1
3
2
1
0
4
3
2
1
3
2
1
0
8
6
4
2
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
break
False
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
What does print("hello) display?
hello
gives you an error
"hello"
"hello
How do you ask an input from a user?
name = int("what is your name")
name = input(what is your name?)
input = name("what is your name?")
name = input("what is your name?")
____________ is information the user sends to the computer
Software
Input
Secondary Memory
Program
How will the following code look on the screen?
print ("I love programming.")
print ("I love programming.")
"I love programming."
"I love programming."
I love programming.
I love programming.
I love programming. I love programming.
I LOVE PROGRAMMING
I LOVE PROGRAMMING
What will be the output?
name = "Dave"
print (name)
Dave
'Dave'
name
(name)
Match the following values with their Python data types
7.3
float (decimal)
4
int (integer)
"Hello"
str (string)
True
bool (boolean)
Order the below into the correct order for an assignment statement in Python. Not all options are used.
(a) (b) (c)
What is the result of the following Python print statement?
print(4 + 2 * 3 - 6)
What will this code output?
print("confusion")
Confusion
confusion
Syntax Error
In the following code, what is happening?
foo = "bar"
A variable named foo is being created, with a value of "bar"
A variable named bar is being created, with a value of "foo"
If foo is equal to 3 and x is equal to 4, what is the value of foo after this operation?
foo = foo + x
4
12
7
34
What will the following code output?
biff = 3.4
print(biff)
An error because 3.4 is not a string
3.4
"3.4"
3
Reorder the following to create a valid Python statement
myVariable
=
"
Hello World
"
What is type casting?
It allows a piece of data to have it's data type changed, e.g. an integer could be changed to a string.
It allows the program to display the value of a variable on the screen.
It allows the program to collect data from the keyboard.
It allows the programmer to display the value of a variable while the program is running.
Which of the following input commands would allow the user to receive and store a string from the keyboard?
string = input("Please enter a string:")
string = int(input("Please enter a string:"))
string = float(input("Please enter a string:"))
string = bool(input("Please enter a string:"))
What is printed by the following code?
x = int(6.8)
print(x)
Nothing, it's a syntax error.
6
7
6.8
A variable is a named value that can be changed in the program.
False
True
Which value is a String?
64
"cat"
True
0.5
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.
Which writes a message for the user?
input()
myVar="Hi"
print("Hello!")
max=100
print(Hello world!)
Print("Hello world!")
print(3+4)
print(3*4)
print("3*4+5")
print(9/3)
What will be the output?
name = 'Dave'
greeting = "Good morning " + name
print (greeting)
Good moning 'Dave'
Good morning Dave
Good morning name
Good morning + Dave
(a) are special built-in routines that do a specific job unique.
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?
*
#
&
$
Choose the TWO correct data types from the list below
Integer
Real
Fake
Short
Why do we need to convert data types in Python?
Because Python doesn't know about data types
Because Python stores data types as String by default
