WorksheetsY10 - Programming EOU
Total questions: 158
Worksheet time: 2hrs 43mins
What type of data is the following?: X = "195.67"
Float
String
Boolean
Integer
What type of variable is the following?: Y = False
Float
String
Integer
Boolean
Variables have three things:
Numeric, string, Boolean
Integer, float, string
name, type, value
function, value, name
When you want to print something to the screen you should use
The keyboard to type it
The computer Display
A monitor
a print statement
print("Python " * 3); will print out what
Python 3 Python 3 Python 3
Python Python Python
PythonPythonPython
Python*3 Python*3 Python*3
Which one to the following Python programs will not run?
num = 4
greeting = "Hello"
print(num + greeting)
grade = 98.7
letterGrade = "A+"
print(str(grade) + letterGrade
studentNum =80
print("studentNum")
print("Hello World!")
Which of the following is NOT a program that will produce the following output?
SeasonSeasonSeason
word = "Season" * 3
print(word)
word = "Season" + "Season" + "Season"
print(word)
num = 3
word = "Season" * 3
print(word)
word = "Season"
print(word)
print(word)
print(word)
float, integer, boolean, and string are all examples of what?
Variables
Data Types
Words
Concatenation
The following statement/code snippet is an example of what?
color = blue
All is correct
Variable/variable assignment
Variable declaration
Variable initialization
What will be the output of
print (a + b)
12
3
1 + 2
"a + b"
What will be the output of
print (c + d)
34
7
3 + 4
"3 + 4"
What will be the output of
print (a x b)
12
1
2
"1x2"
What will be the output of
print (a x c)
"axc"
"1x3"
"3"
3
What will be the output of
print (a x d)
"axd"
"1x4"
"4"
4
What will be the output of
print (a x "c")
c
"1c"
"c"
1 x "c"
What will be the output of
print (b x "d")
b x "d"
dd
2 x 4
8
What do we use variables for?
To store data
Print data
Produce functions
What does int() represent?
internet
integer
intel
input
To get the users input what function do we use?
input
input<>
input()
INPUT()
What type of data is the following?: X = "195.67"
Float
String
Boolean
Integer
What type of variable is the following?: Y = False
Float
String
Integer
Boolean
What will be the output of
print (a + b)
12
3
1 + 2
"a + b"
What will be the output of
print (c + d)
34
7
3 + 4
"3 + 4"
What will be the output of
print (a x b)
12
1
2
"1x2"
What will be the output of
print (a x c)
"axc"
"1x3"
"3"
3
What will be the output of
print (a x d)
"axd"
"1x4"
"4"
4
What is the process of converting one data type to another called?
Data conversion.
Type Casting.
Type Conversion.
Concatenation.
What function converts the data in a variable into a 'integer'?
int()
str()
bool()
float()
What function converts the data in a variable into a 'float'?
int()
flt()
bool()
float()
What function converts the data in a variable into a 'string'?
str()
float()
bool()
string()
What does this built-in function do?
input()
Opens the CD tray.
Prompts the user to enter data.
Displays the word 'input'.
Exits the program.
How do you ask for the user to input their name?
name = int("what is your name")
print("What is your name?")
input = name("what is your name?")
name = input("what is your name?")
By default any data inputted by the user is of data type string in python.
True
False
What will be the output of the following command?
x = int(3.6)
print(x)
3
4
Logical error - Can't cast a float value to an integer as data will be lost.
What will be the output of the following command?
x = float(3)
print(x)
Logical error - Can't cast a integer value to an float as data will be added.
3.0
3
What will be the output of the following command?
x = str(3)
print(x)
3
3.0
'3'
What will be the output of the following program, if the user entered 20 and then 41?
Number1 = input("Enter the first number: ")
Number2 = input("Enter the second number: ")
print(Number1 + Number2)
20 41
Syntax error.
61
2041
What can you add to the following code so that python recognises that they are numbers?
Number1 = input("Enter the first number: ")
Number2 = input("Enter the second number: ")
print(Number1 + Number2)
int()
float()
Use a print statement to tell the user to enter a number.
integer()
Fill in the missing section for the code below:
areaOfSquare = (a) (input("Enter area of square: "))
What will be the output of the following program?
gameOnePoints = 200
gameTwoPoints = "456"
print(gameOnePoints + gameTwoPoints)
Logical error - Can't add an integer and string together.
656
"656"
Enter the missing keyword for the program below:
name =_____("Enter name: ")
input
Bob
Input
Which of the following variable names can be used in a Python program?
first_name
Name_1
First Name
Name
Which one of the following is the most appropriate name for a variable that stores data about how tall someone is?
Num1
Value
x
height
Which of the following correctly describes the programming concept sequencing?
When a set of instructions is repeated
When a set of instructions is carried out in order
Involves asking a question to which the answer is either true or false
Programs that use blocks of instructions that work with each other
What will the program output?
animal = 'zebra'
print(animal)
'Zebra'
zebra
Animal
Zebra
What is wrong with this line of code:
input('What is your name?')
Input should be changed with Print
There is no variable assigned to the input
The question mark should not be included
The brackets are positioned in a wrong way
A variable name must start with a letter and it cannot start with a number
True
False
Variable names are case sensitive. Which means name, Name, NAME are all different variables.
True
False
What will be the output of this code?
Hello name pleased to meet you
John
Hello John pleased to meet you
HelloJohnPleased to meet you
When you work with decimal numbers in Python, which data type is the most suitable?
Integer
Float
String
A list is given below:
veg = ["carrot", "onion", "cabbage", "potato", "leek"]
Which vegetable would be retrieved with
veg[1]?
carrot
onion
cabbage
potato
leek
Here is a list:
veg = ["carrot", "onion", "cabbage", "potato", "leek"]
How would you retrieve the element from the list that contains the word leek?
veg[5]
veg[4]
veg[3]
veg[2]
Consider the code given here. What will be the output of the given line of code?
print (fruits)
[raspberry, apple, pear, banan, orange]
[apple, pear, banana, orange,rasberry]
the code will not run
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 is the correct way to declare a variable 'a' with the value 100 in Python?
var a = 100
int a = 100
a = 100
declare a = 100
Which of the following is NOT a data type in Python?
list
array
dictionary
tuple
What is the output of the following code snippet? ```python if 9 > 2: print("Nine is greater than two!") else: print("Two is greater than nine!") ```
Nine is greater than two!
Two is greater than nine!
Error
None of the above
Which of the following is used to represent a boolean value of 'true' in Python?
true
True
1
Both B and C
How do you find the length of the string "Python" in Python?
len("Python")
length("Python")
size("Python")
"Python".length()
What is the result of the following code snippet? ```python x = int(2.8) ```
2
2.8
3
Error
Which of the following is a constant in Python by convention?
CONSTANT
constant
Constant
_constant_
What is the correct way to concatenate two strings, `a = "Hello"` and `b = "World"`?
a + b
a.concat(b)
concat(a, b)
a & b
What is the output of the following code snippet? ```python print(bool("False")) ```
False
True
0
Error
How do you convert the string "123" into an integer in Python?
int("123")
str(123)
"123".toInt()
parseInt("123")
What is the name of the variable in this program?
colour
input
there is no variable
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
What will the code do?
nothing
display Hello Bob
display I don't know you
display Hello
If the user enters 60, what is the output?
You are old!
You are middle-aged!
You are young!
Error message
holds whole numbers
holds a decimal point in a number
Logical operators:
True if both operands are true
x and y
x or y
not x
Logical Operators:
True if either of the operands is true
x and y
x or y
not x
Logical Operators:
true if operand is false
x and y
x or y
not x
Comparison Operators:
Select the correct operator for Greater Than:
>
<
^
v
Comparison Operators:
Select the correct operator for Less than
>
<
^
v
Comparison Operators:
Select the correct operator for equals to
=
==
===
====
Comparison Operators:
Select the correct operator for not equal to
=!=
!
=!
!=
Comparison Operators:
Select the correct operator for Greater than or Equal to:
>=
=>
=)
<=
Comparison Operators:
Select the correct operator for less than or equal to
<=
=>
>=
==
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 is a for loop used for in Python?
Iterating over a sequence
Defining a function
Creating a class
Handling exceptions
Which of the following is NOT a sequence that a for loop can iterate over?
Integer
Dictionary
Tuple
List
What does the break statement do in a for loop?
Skips the current iteration
Continues with the next iteration
Stops the loop before it has looped through all the items
Restarts the loop
What does the continue statement do in a for loop?
Exits the loop
Skips the current iteration and continues with the next
Stops the loop
Restarts the loop
What does the range() function do?
Returns a sequence of numbers
Returns a list of strings
Returns a dictionary
Returns a set of tuples
What will be the output of the following code? for x in range(2, 6): print(x)
2 3 4 5 6
2 3 4 5
0 1 2 3 4 5
3 4 5 6
What is the purpose of the else block in a for loop?
To execute a block of code if the loop is infinite
To execute a block of code if the loop is skipped
To execute a block of code before the loop starts
To execute a block of code when the loop is finished
What will be the output of the following code? for x in range(6): if x == 3: break print(x) else: print('Finally finished!')
0 1 2 3
0 1 2
0 1 2 3 4 5 Finally finished!
0 1 2 Finally finished!
What is a nested loop?
A loop with a break statement
A loop inside a loop
A loop that runs infinitely
A loop with a continue statement
What will be the output of the following code? for x in range(1, 10, 2): print(x)
1 2 3 4 5 6 7 8 9
1 3 5 7 9
2 4 6 8 10
1 2 3 4 5 6 7 8 9 10
What will be the output of the following code? for x in range(4): if x == 2: continue print(x)
0 1 2 3
0 1 3
0 1 2
1 2 3
What is the purpose of the pass statement in a for loop?
To exit the loop
To skip the current iteration
To do nothing and continue
To restart the loop
what is the name of the variable used in the following code?
counter
for
#
1,2,3,4
What does the following program display?
1,2,3,4
1,2,3,4,5
counter,counter,counter,counter,counter
0,1,2,3,4,5
Look at the following code, what will it generate
1,2,3,4,5,6,7,8,9,10,11,12
0,1,2,3,4,5,6,7,8,9,10,11,12
1,2,3,4,5,6,7,8,9,10,11,12,13
0,1,2,3,4,5,6,7,8,9,10,11,12,13
FOR loops are
loops which run an unknown number of times
loops which run for a specific number of times
the same as if statements
not part of programming
When would you use a FOR loop?
When you know how many times you want something to loop
When you don't know how many times you want it to loop
A FOR Loop is...
A condition controlled loop
A count controlled loop
A WHILE Loop is...
A condition controlled loop
A count controlled loop
The following array is created in a program: " DIREWOLVES = ["Nymeria","Shaggy Dog","Ghost","Lady","Grey Wind","Summer"]
What is the item stored in DIREWOLVES [2] ?
"Shaggy Dog"
"Ghost"
Which of the following facts about arrays is TRUE?
Arrays can contain items of different data types
Arrays can only contain items of a single data type
Lists and arrays are the same thing
An arrays is a type of variable
A program contains a 2D array ("CUSTOMER") storing customer numbers, first names and surnames
What data is held in stored in CUSTOMER (2,3)?
Amrit
Kahn
Taylor
1003
A program contains a 2D array ("CUSTOMER") storing customer numbers, first names and surnames
What data is held in stored in CUSTOMER (0,2)?
1004
Smith
Amrit
1003
A program contains a 2D array ("CUSTOMER") storing customer numbers, first names and surnames
Where in the array is the data item "Kahn" stored?
(2,3)
(4,1)
(2,2)
(3,3)
Arrays are an example of...
Dynamic Data Structures
Static Data Structures
Strings
Integers
Which of the following statements about ARRAYS are true?
Arrays are more useful than individual variables for storing related data items
Arrays are less wasteful that lists in terms of memory
It is possible to iterate through the items in an array
The memory used to store the data in an array, is allocated when the array is set up
A programmer wants to store a set of data about the top grossing films of all time. He wants to include Film Name, Director, Genre, Year of release, and Money earned. Which data structure would be appropriate?
A list
An array
In an array, what is the first numbered position in which data can be stored?
Position 0
Position 1
What term is used to describe an individual position of an element in an array?
Index
Pointer
Variable
List
Which of the following would be an appropriate use of a 2D array?
Storing a list of colours
Storing a list of random numbers
Storing positions on chessboard
Storing a list of first names
Here is a data structure created in a program. Which of the following statements most accurately describes this data..?
"hogwarts" is a list
"hogwarts" is an array
"hogwarts" could be both an array and a list
"hogwarts" cannot be an array
What is printed by the following lines of code?
eggs
bread
2
sugar
25
25
undefined
20
A programmer is creating a simple grid based video game. The blue square represents start position of the player, which is stored in a 2D array. Which of the following is correct?
Player_pos = [1,5]
Player_pos=[2,5]
Player_pos=[5,1]
Player_pos=[5,2]
