Log in
Sign up for FREE
arrow_back
Library
ifs Test Python
By Mickey Arnold
star
star
star
star
star
Share
share
Last updated almost 2 years ago
40 questions
Add this activity
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Question 1
1.
What is output by the code below?
hour = 8
if hour > 12:
print(hour-12, "O'Clock")
else:
print(hour, "O'Clock")
Question 2
2.
What is output by the code below?
score = 200
highScore = 190
if score > highScore:
print("You beat the high score by", score-highScore, "points!")
else:
print("You needed", highScore - score, "points")
Question 3
3.
What is output by the code below?
numCards = 2
if numCards < 2:
print("Uno!")
else:
print("Keep Playing")
Question 4
4.
What is returned by the call
greeting(17)
?
def greeting(time)
if time < 12:
return "Good Morning"
elif time < 17:
return "Good Afternoon"
elif time < 22:
return "Good Evening"
else:
return "Good Night"
Question 5
5.
Consider the incomplete class shown below. The method addScore adds points to score if life is positive.
def addScore(points):
/* blank */
score += points
Which of the following code segments shown below could be used to replace
/* blank */
so that sum will work as intended?
I. if (life != 0):
II. if (life > -1):
III. if (life > 0):
I only
II only
III only
I and II only
I and III only
Question 6
6.
What is output by the code below?
x = 5
if (x%2==0):
print("No Remainder")
else:
print("Remainder of One")
No Remainder
0
5
Remainder of One
2
Question 7
7.
What is output by the code below?
note = 2
if note == 1:
print("Quarter note")
elif note == 2:
print("Half note")
elif note == 4:
print("Whole note")
Quarter note
True
Half note
Full note
There is no output
visibility
View drawing
Question 8
8.
What is output by the call
tooShort(54)
?
def tooShort(height):
if height < 48:
print("You cannot ride this roller coaster")
else:
print("Get in line to ride")
False
True
There is no output due to a syntax error.
Get in line to ride
You cannot ride this roller coaster
Question 9
9.
What is output by the call
checkFood(1)
?
def checkFood(timer):
if timer > 15:
print("Go play games")
elif timer > 10:
print("Stay close by")
elif timer > 1:
print("Check food")
elif timer > -2:
print("Take food out")
else:
print("Food has burnt")
Take food out
Food has burn
Go play games
Check food
Stay close by
Question 10
10.
What is output by the code below?
numPens = 3
if numPens < 2:
print("I don't have any extras")
else:
print("Yes, you can borrow one")
I don't have any extras
Yes, you can borrow one
False
True
There is no output due to a syntax error.
Question 11
11.
Assume the following code in within a class.
What is output by the code below if self.space is 19?
def freeSpace(self)
if self.space > 50:
print("You have a lot of space")
elif self.space > 20:
print("You don't have that much space")
elif self.space > 2:
print("You have very little space")
else:
print("You have no space")
Question 12
12.
What is output by the code below?
light = "red"
if light == "green":
print("Drive")
else:
print("Stop")
Drive Stop
red
Drive
green
Stop
Question 13
13.
What is output by the code below?
grade = 85
print (grade < 70)
Question 14
14.
What is output by the code below?
if 3 < 2:
print("Less Than")
else:
print("Greater Than")
3 > 2
There is no output due to a syntax error.
False
Less Than
Greater Than
Question 15
15.
What is output by the code below?
lvl = 6
if lvl < 2 and lvl > 0:
print("You are a white belt")
elif lvl < 5 and lvl >= 2:
print("You are a blue belt")
elif lvl < 8:
print("You are a purple belt")
You are a blue belt
You are a purple belt
2
You are a white belt
There is no output.
Question 16
16.
What is output by the call
printMult(8)
?
def printMult(times):
if times > 3:
print(times)
if times > 2:
print(times)
if times > 1:
print(times)
if times > 0:
print(times)
8 8 8
8
8 8 8 8
8 8 8 8 8
8 8
Question 17
17.
What is output by the code below?
print("left" == "right" and False == False)
left right False
False
right
True
left
Question 18
18.
What is output by the code below?
answer = "cup"
if answer != "yes":
print("Game Over")
else:
print("Game Start")
Question 19
19.
What is output by the code below?
x = 65
print(x < 30 or x < 90)
True
65
30
False
90
Question 20
20.
What is the value of lightsOn after the call
house.lights(20)
?
def lights(self, time):
if time < 6:
self.lightsOn = False
elif time < 22:
self.lightsOn = False
else:
self.lightsOn = True
Question 21
21.
What is output by the code below?
gradeLvl = 9
if gradeLvl > 8:
print("High School")
if gradeLvl > 5:
print("Middle school")
else:
print("Elementary school")
High School
High School
Elementary School
Middle School
Elementary School
High School
Middle School
Question 22
22.
What is returned by the call
minToHour(120) ?
def minToHour(time):
if time >= 60:
print(time / 60.0, "hours")
else:
print("Less than an hour")
1.5 hours
2 hours
2.0 hours
Less than an hour
1 hours
visibility
View drawing
Question 23
23.
What is output by the code below?
x = 200
width = 3.2
print("Moving Right")
if x * width > 800:
print("Hit Edge")
Moving Right
Hit Edge
True
Moving Right
False
Hit Edge
visibility
View drawing
Question 24
24.
What is output by the call
warning(65)
?
def warning(hp):
if hp > 50:
print("You're fine.",)
if hp > 90:
print("You don’t need healing.")
else:
print("You could heal.")
else:
print("You're not fine.",)
if hp > 20:
print("You should heal.")
else:
print("Heal NOW!")
You're not fine. You should heal.
You're not fine. Heal NOW!
You're fine. You could heal.
You're not fine.
You should heal.
You're fine.
You don’t need healing.
Question 25
25.
What is output the call
addBelow(15)
?
def addBelow(num):
temp = num
ans = num
if temp > 14:
temp -= 2
ans += temp
if temp < 8:
temp += 2
ans -= temp
if temp > 6:
temp -= 5
ans += temp
print(ans)
visibility
View drawing
Question 26
26.
Which of the following could correctly fill
/* blank */
in method
isOdd()
?
# method isOdd should return True if num is odd and False if num is even
def isOdd(num):
/* blank */
return True
return False
if( num % 3 == 1):
if( 2 % num == 0):
if( not num % 2 == 0):
if( num % 2 == 0):
if( 3 % num == 0):
Question 27
27.
What is output by the code below?
greaterThan = 15 > 10
print(greaterThan)
False
There is no output due to a syntax error
15
True
10
Question 28
28.
What is returned by the call
makeCookies("yes")
?
def makeCookies(answer)
if answer == "yes":
return True
else:
return False
Question 29
29.
What is output by the code below
if
random.randint(0,8)
returns a 5?
def magic8Ball(question):
print(question)
num = random.randint(0,8)
if num == 1 and num < 3:
print("As I see it yes")
elif num == 3:
print("Don't count on it")
elif num == 4:
print("Without a doubt")
else:
print("Reply hazy try again")
Question 30
30.
What is the output of the call
openDoor(5)
?
def openDoor(key):
if key == 1:
print("Open Blue Door")
elif key == 2:
print("Open Red Door")
elif key == 3:
print("Open Green Door")
elif key == 4:
print("Open Yellow Door")
Open Blue Door
There is no output.
Open Yellow Door
Open Red Door
Open Green Door
Question 31
31.
What is output by the call
whereRoom(165)
?
def whereRoom(roomNum):
if roomNum > 199:
print("2nd Floor")
else:
print("1st Floor")
if roomNum % 100 > 50:
print("West Wing")
else:
print("East Wing")
2nd Floor
East WIng
1st Floor
2nd Floor
1st Floor
West Wing
2nd Floor
East Wing
Question 32
32.
What is output by the code below?
batteryLife = 25
if batteryLife < 10:
print("Charge Battery")
elif batteryLife < 20:
print("Low Battery")
elif batteryLife == 100:
print("Fully Charged Battery")
elif batteryLife > 90:
print("Mostly Charged Battery")
There is no output.
Charge Battery
Low Battery
Mostly Charged Battery
Fully Charged Battery
Question 33
33.
What is output by the code below?
y = 11
if(y == 21):
print("Black Jack")
print("Game Finished")
Black Jack
Game Finished
Black Jack
There is no output due to a syntax error.
False
Game Finished
Question 34
34.
What is output by the code below?
month = 11
if month == 3:
print("Spring Break")
elif month == 11:
print("Thanksgiving Break")
elif month == 12:
print("Winter Break")
else:
print("No big break")
Question 35
35.
What is output by the code below?
eggs = False
if eggs:
print("We need eggs")
else:
print("Start baking")
Question 36
36.
What is output by the code below?
temp = 33
if temp >=212:
print("Boiling")
elif temp <= 32:
print("Freezing")
Freezing
There is no output
True
19
Boiling
Question 37
37.
What is output by the code below?
print("cat" == "dog")
dog
False
cat
cat dog
True
Question 38
38.
What is output by the code below?
pie = "apple"
print("Shopping List \neggs \nflour")
if pie == "cherry":
print("cherries")
cherries
Shopping List
eggs
flour
Shopping List
eggs
flour
cherries
cherry
Shopping List \neggs \nflour
Question 39
39.
What is output by the call
takeDmg(20)
and hp = 120 ?
def takeDmg(dmg)
hp -= dmg
if hp = 0:
print("Game Over!")
else
print(hp)
There is no output due to a syntax error.
Game Over!
15
-5
20
Question 40
40.
What is output by the code below if the right arrow is pressed?
if event.type==KEYDOWN:
if event.key==K_UP:
print("Up")
elif event.key==K_DOWN:
print("Down")
elif event.key==K_LEFT:
print("Right")
elif event.key==K_RIGHT:
print("Left")
Left
Down
Up
Right
There is no output