NEW
Font size
WorksheetsGrade 12-Python selection&iteration
Total questions: 15
Worksheet time: 26mins
In programming, what is iteration?
The repetition of steps within a program
The order in which instructions are carried out
A decision point in a program
Testing a program to make sure it works
Which two statements are used to implement iteration?
IF and WHILE
ELSE and WHILE
FOR and WHILE
IF and ELSE
The condition for a while loop to continue could include which of the following?
While something equals something
While something is greater than something
While something is True
All of these
number=number-1
5
4
3
2
1
4
3
2
1
0
5 4 3 2 1
4 3 2 1 0
10 8 6 4 2
10
8
6
4
2
2 4 6 8 10
10 9 8 7 6 5 4 3 2 1
12 17 22
5
12
5 10
Hello world!
Hello world
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
Error
Which of these is NOT a loop in python?
for loop
while loop
nested loop
if loop
What is the error in this code?
incorrect variable name
incorrect indentation
incorrect speech marks
incorrect loop
If you want more than one option for your code, what do you use (after if)?
elif
elseif
else
people = ["John", "Rob", "Bob"]
print (people[1])
what would this result be?
John
Rob
Bob
What is the result of the code:
team = Cowboys
if team = Cowboys:
print "Dallas is #1"
team
Cowboys
Error
Dallas is #1
Suppose you want to determine if a student is ready to graduate. The 3 criteria for graduation are that the student has earned at least 120 credits, their major GPA is at least 3.0 or their general GPA is also at least 3.5
Which Boolean expression would be the correct test for Python code?
numCredits >= 120 and majorGPA >= 3.0 or overallGPA >= 3.5
numCredits > 120 and majorGPA > 3.0 and overallGPA >3.5
numCredits > =119 and majorGPA >= 3.0 and overallGPA >= 3.5
Write the line of code which initialize the counter variable
x<20
x=x+1
name=input("Enter your name")
x=0
In the above program if the value of 'x' is 23 and 'number' is 24, what will be the output?
23 24
23
23
24
3 4
