Font size
WorksheetsG8 2nd Test Review
Total questions: 100
Worksheet time: 1hrs 16mins
The command that will print a line of command on the program is:
echo
hey, Alexa
speak
Which of the following is a Python command
@echo off
print ("")
print "name"
echo.
In Python, a variable needs to
start with a letter or underscore
be stated before "print"
have % symbols on either side
Variable????? We don't need variables!!!!
Data that is collected and sent to a computer is
input
output
storage
process
Presenting the results back to a user is known as
input
output
storage
processing
Carrying out instructions is known as
input
output
processing
storage
print (name + " is " + age " years old") This is an example of:
input
output
processing
storage
Mr. Whiting is 45 years old. This is an example of:
input
output
processing
storage
In Python, to have text stated for the user to see, we use:
" "
% %
( )
? ?
In Python, to make remarks that the computer will ignore, we use:
rem
#
IGNORE!
( )
The Boolean operator that means "not equal to" is
XX
!=
<>
_
Which is correct?
if num1=10:
if num1==10:
if num1==10;
if num="10";
When writing an if/else statement, you
always indent the line after the condition
never indent the line after the condition
capitalize every word
put a colon at the beginning and the end
Which is correct?
if num1==42:
print("You have discovered the meaning of life!")
if num1==42...
print("You have discovered the meaning of life!")
if num1==42:
print "You have discovered the meaning of life!"
if num1==42:
print( You have discovered the meaning of life!)
In Python, the command "while" will create a:
loop
variable
function
a chocolate cake
In Python, iteration is another word for a:
loop
variable
function
command
In a loop, as long as the user enters an answer that is "true,"
the command repeats itself
the program ends
the programs starts over
the user gains 10 points
How do you declare a variable in python?
score = 100
int score = 100;
def score(100):
score 100
What are TWO ways I can add 100 to the variable "score"?
score += 100
score = score + 100
score + 100
score = 100
Which symbol represents modulo, which means to divide two numbers and keep the remainder?
%
**
//
/
Which is the correct way to use the floor division operator, which divides two numbers and throws out the remainder?
score = score//10
score = score/10
score//10
score = score** 10
Which operator raises one number to the power of another?
**
*
^
&
What's wrong with this if statement?
it should have a "==" operator
line two shouldn't be tabbed over
it needs parenthesis ( ) around the condition
it shouldn't have a colon (:) at the end of line 1
What will this print?
you lose
you win
nothing
error message
What will this code print?
you lose
you win
nice try
nothing
What will this code print?
you lose
you win
nice try
nothing
What will this code print?
1 through 10
1 through 9
0 through 10
0 through 9
What will this code print?
2 through 20, counting by 2s
2 through 22, counting by 2s
4 through 20, counting by 2s
4 through 22, counting by 2s
What will this code print?
5,4,3,2,1
4,3,2,1
5,4,3,2,1,0
nothing
What will this code print?
2,4,6,8
2,4,6
4,6
2,3,4,5,6,7,8
What will this code print?
'a', and then any letter the user types until they press 'q'
Any letter the user types until they press 'q'
nothing
'a' until the user types 'q'
What will this code print?
nothing
'b', and then any letter the user types until they press 'q'
'b' until the user types 'q'
any letter the user types until they press 'q'
What's wrong with this code?
nothing, it works fine
it's missing arguements in the parenthesis ( )
it's missing a return value
line 3 should be tabbed over
What is a input?
To plug in something.
A function that allows us to ask the user to enter some data.
Data displayed on a screen.
A function
What in the name of the variable in this Python code?
name
input
("What is your name")
Which of these is not an arithmetic operator?
+
-
*
=
What is the output of the following code snippet?
x = 5
if x > 3:
print("Greater than 3")
else:
print("Less than or equal to 3")
Greater than 3
Less than or equal to 3
Invalid syntax
No output
What is the output of this code?
X
Y
Error
print(“What year is it?”)
year = int(input())
What datatype is the variable year?
integer
float
string
print(“Enter a price.”)
money = float(input())
What datatype is the variable money?
integer
float
string
print(“Please enter your age.”)
age = int(input())
What datatype is the variable age?
integer
float
string
print(str(i) * 5)
print("i" * i)
print("i" * i)
print(str(i) * i)
Which of the following for loops would print the following numbers?
3
5
7
9
for i in range(3, 10, 2):
print(i)
for i in range(3, 9, 2):
print(i)
for i in range(9):
print(i)
for i in range(3,9):
print(i)
What would be the output of the following code:
for i in range(3):
print(5)
0 1 2
3 3 3 3 3
5 5 5
0 1 2 3 4
What is the output?
True
NIL
True
NIL
True
NIL
NIL
What is the output?
3
3
7
3
5
7
7
Are there any syntax errors?
No
Quotations are not needed on line 1
Elif does not exist
There should be a colon on line 7
If the user inputs : 2 , what does the following code snippet print ?
Yes
No
May be
Nothing printed
Error
There can be an else statement without an if statement
FALSE
TRUE
It is possible to execute both the statements under if and else at the same time.
TRUE
FALSE
When this code is run, it prints "Ok, sure." every time, no matter what number the user enters. Why?
its the last line of code
x is an int and the conditions checked are equality to strings
The else will always override the elif
You can't have both an if and an elif
How many elif's can you have chained together in an if statement?
as many as you want
only 1, followed by an else
up to and including 3
only 2 followed by an else
What is the final result of the expression 2**3?
6
8
2
1
Why the code is incorrect?
Because is missing the indentation in the second line
The keyword "print" should be in capital letter
The two points are unnecessary
What is a variable?
Are expressions that evaluate to either true or false. They are mostly used to determine Program Flow through if statements and while loops.
Is a data item whose value cannot change during the program's execution.
Are used to store information to be referenced and manipulated in a computer program.
In the following code:
X=float("Enter a number")
x=float("Enter a number")
print(x)
What is the number of variables?
One
Two
Three
What is the output of the following code?
x = 7
if x % 2 == 0:
print("Even")
else:
print("Odd")
Even
Odd
7
Error
What is the output of the following code?
y = 8
if y % 2 == 0:
print("Even")
else:
print("Odd")
Even
Odd
8
Error
What is the output of the following code?
z = 12
if z > 10:
print("z is greater than 10")
else:
print("z is less than or equal to 10")
z is greater than 10
z is less than or equal to 10
z is equal to 10
Error
What's the main advantage of using a for-loop, rather than manually repeating the code?
It reduces the chance of making errors by keeping the code concise..
What is the output of the following code?
for i in range(3, 4):
print(i)
What is the main purpose of a while loop in Python?
To execute a block of code while a certain condition is true.
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
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
1,2,3,4
#What is the output?
1,2,3,4,5
0,1,2,3,4
1,2,3,4
5,4,3,2,1
Which of the following for loops would print the following numbers?
3
5
7
9
for i in range(3, 10, 2):
print(i)
for i in range(3, 9, 2):
print(i)
for i in range(9):
print(i)
for i in range(3,9):
print(i)
Which kind of loop would be used?
I need a program that will keep letting me add a monthly payment for 12 months.
FOR Loop
WHILE Loop
Which kind of loop would be used?
I need a guessing game program that will let me keep guessing until I get the right answer.
FOR Loop
WHILE Loop
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
name = “Alison”
number = len(name)
print(number)
4
3
2
1
3
2
1
0
4
3
2
1
3
2
1
0
A loop that is inside of another loop is known as a what?
Infinite loop
Loop to loop
While Loop
Nested Loop
The equivalent of the above for loop using the while syntax would be
What is the issue with the following code?
If condition will never be fulfil
print cannot be use multiple times
age is always lesser or equals to 18
Printing conflicting statement,, should have an else statement
What is the issue with the following code?
age 18 should already be an adult
no if statement, compile error SyntaxError
missing elif statement
invalid print statement within else condition
FOR loops are
loops which run an unknown number of times
loops that iterates over a sequence in Python
loops which run a known number of times
repeatedly execute a statement as long as the condition provided stays true
WHILE loops are
loops which run an unknown number of times
repeatedly execute a statement as long as the condition provided stays true
loops that iterates over a sequence in Python
loops which run a known number of times
4
3
2
1
3
2
1
0
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
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
1,2,3,4
for number in range(6):
print(number)
What will this code do?
Print Numbers 1-11
Print Numbers 1-10
Print Numbers 2-10
Print Error
What will be the output of this code?
2
4
6
12
What will be the output of this code?
2
4
6
12
What will be the output of this code?
1
3
4
5
What is the value of num when this loop completes?
num = 0
for i in range(2, 8, 2):
num += i
2
8
12
20
Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?
for i in range(0, 5):
for i in range(5):
for i in range(0, 5, 1):
for i in range(5, 0, 1):
What will be the output after the following statements?
true
not false
false
not true
error
What output will be produced by the following segment of code?
Too Low
Too High
Syntax Error
No Output - Logic Error
The result of this program:
Friday = False
if Friday:
print "Jeans day!"
else:
print "Uniform day"
Jeans day
Today is Friday
Uniform day
Not Friday
What is the output?
True
False
condition1
condition2
What is the output?
3
3
7
3
5
7
7
