Worksheets3rd SW - ZLGA - Fund. of CS
Total questions: 45
Worksheet time: 27mins
A while loop can be used in which of the following situations?
Repeat a set of statements till a condition remains True.
Repeat a set of statements a finite or an infinite number of times.
Iterate through a string, list, and tuple.
All of the above
Kind of loop used when you know the number of times you want it to repeat
list
for
while
if
Which variable correctly stores a string value?
greeting = hello
greeting = 81
greeting = "hello"
greeting = 45.8
__________ are used to make logical associations between boolean values.
Operands
Operators
logical operators
mathematical operators
Loop that runs till the condition is true
list
while
for
if
Kind of loop used when you know the number of times you want it to repeat
list
for
while
if
What is an iteration?
A single loop
Repeated execution of a list of statements.
Repeated execution of loops
Repeated execution of variables
Terminates the loop statement and transfers execution to the statement immediately following the loop
pass statement
continue statement
break statement
Causes loop to skip the remainder of its body and immediately retest its condition to reiterating
continue statement
break statement
pass statement
break will break out of an iteration
true
false
continue will move to the next iteration
true
false
A range will go to the last number listed but not include it
true
false
If there is a circumstance where you do not want to break out of a loop, but just skip a certain value, you would use
skip
break
continue
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
Which kind of loop would be used?
I need a revision program that will run through revision questions 4 times.
FOR Loop
WHILE Loop
You can use one or more loop inside any another while, for or do..while loop.
while loop
for loop
nested loop
infinite loop
This loop condition never becomes FALSE.
while loop
for loop
nested loop
infinite loop
Which one of the statements below will cause an error?
ans = “hi” * 8
ans = “hi” + 9
ans = “hi” + “hi” + “hi”
ans = (“a” * 4) + “b”
Which of the following statements is true about print statements?
I. In order to print a string literal, the string must be enclosed in quotes.
II. Each print statement will be printed on its own line.
III. Print statements will not let you print string and number characters in the same statement.
IV. Print statements are how you display text on the screen.
I, IV
II, III
I, II, IV
I, III, IV
Suppose you have a variable defined a = "4". What is the variable type of a?
str
int
float
number
Which of the following choices is NOT a Python variable type?
int
str
float
number
In what order should these statements be executed in order to get input from the user and print out the result?
A) response = input("Do you like cheese? ")
B) print("You have chosen " + confirm)
C) print("You responded " + response)
D) confirm = input("Are you sure? ")
A, B, C, D
B, C, A, D
A, C, D, B
C, B, A, D
What is the output?
more than 7
more than 23
spam
7
Pieces of code that only run "under certain conditions":
conditional statements
control flow statments
syntax
variables
Which symbol means "not equal to"?
==
<=
>=
!=
Which character must be at the end of the line for if?
:
;
.
{
What does the = = symbol mean in Python?
Equal to or shows equality
Not Equal
Code that will be skipped
End of clause
What will be displayed at the end of the program?
Case 1
Case 2
Nothing will be displayed.
Case 1 and Case 2
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
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 part of an if statement should be indented?
All of it
The statements within it
the first line
the lines within the brackets
What is the output?
next
stop
next
stop
syntax error - program doesn't work
True/False: The body of an "if" statement will only be executed if the condition is true.
True
False
How many "if" statements can a single program have?
<10
<20
<30
As many as is needed
What is a flowchart used for in programming? click all of the correct answers
planning
building
testing
debugging
Flowcharts can be used for which of the following:
programming
accounting
science
architecture
all of the above
What is the name of the function?
When defining a function, the definition must occur before it is called.
true
false
How do you identify the statements that belong to the body of a function?
Indent those statement the same amount underneath the function "def" statement
Add opening and closing curly braces { and } to mark the start and stop of the function body
Add the "def" keyword to the beginning of each statement
Add the same comment (#) to the right of each statement within the body
Which of the following best describes where you should define your function in your code?
Near the bottom of the source file, after that function is called by any main program code
Always place functions in a separate source file
Near the top of the source file, before that function is called by any main program code
The location is not important, so place the function wherever you like
Which of the following is NOT a Python rule for naming functions?
Functions names can contain letters, numbers and underscores
Function names must be less than 32 characters
The first character in a function name cannot be a number
Function names are case-sensitive
Which of the following statements correctly defines a function named "haunted" that takes a parameter named "apple"?
haunted(apple)
haunted
def haunted(apple):
apple
What will be the output of the following program?
Tracy
hello Turtle
Turtle
hello Tracy
