Comp Sci 1 Semester Review
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
84 Questions
5 points
5
Question 1
1.
What is output by the code below?w = 20while w < 60: w += w // 2print(w)
What is output by the code below?
w = 20
while w < 60:
w += w // 2
print(w)
5 points
5
Question 2
2.
What is output by the code below?r = 1while( r < 50 ): r *= 3print(r)
What is output by the code below?
r = 1
while( r < 50 ):
r *= 3
print(r)
5 points
5
Question 3
3.
What is output by the code below?word = "the paintings"cnt = 0for letter in word: cnt += 1print(cnt)
What is output by the code below?
word = "the paintings"
cnt = 0
for letter in word:
cnt += 1
print(cnt)
5 points
5
Question 4
4.
What is output by the code below?for x in range(3): print("Hi", end = " " )
What is output by the code below?
for x in range(3):
print("Hi", end = " " )
5 points
5
Question 5
5.
What is output by the code below?for x in range(10): print(x, end = " " )
What is output by the code below?
for x in range(10):
print(x, end = " " )
5 points
5
Question 6
6.
What is output by the code below?m = 5while( m > 0 ): m -= 3 print("dog")
What is output by the code below?
m = 5
while( m > 0 ):
m -= 3
print("dog")
5 points
5
Question 7
7.
What is output by the code below?j = 0while( j < 6 ): j += 4print(j)
What is output by the code below?
j = 0
while( j < 6 ):
j += 4
print(j)
5 points
5
Question 8
8.
What is output by the code below?for i in range (5): print(i, end = " " )
What is output by the code below?
for i in range (5):
print(i, end = " " )
5 points
5
Question 9
9.
What is output by the code below?num = 50while num > 0: if num > 20: num -= 10 else: num -= 15 print(num, end = " " )
What is output by the code below?
num = 50
while num > 0:
if num > 20:
num -= 10
else:
num -= 15
print(num, end = " " )
5 points
5
Question 10
10.
What is output by the code below?for x in range 2: print("light", end = " " )
What is output by the code below?
for x in range 2:
print("light", end = " " )
5 points
5
Question 11
11.
What is output by the code below?i = 4cnt = 0while i < 80: i *= iprint(cnt)
What is output by the code below?
i = 4
cnt = 0
while i < 80:
i *= i
print(cnt)
5 points
5
Question 12
12.
What is output by the code below?words = "math and science"i = 0for let in words: if let == "n": print(let) break i += 1
What is output by the code below?
words = "math and science"
i = 0
for let in words:
if let == "n":
print(let)
break
i += 1
5 points
5
Question 13
13.
Which of the following would correctly fill /* code */ in method cntEs()?#method cntEs should return the count of all e’s in wordsdef cntOdds(words):cnt = 0 /* code */return cnt
Which of the following would correctly fill /* code */ in method cntEs()?
#method cntEs should return the count of all e’s in words
def cntOdds(words):
cnt = 0
/* code */
return cnt
5 points
5
Question 14
14.
What is output by the code below?sum = 0for t in range(2, 6): sum += tprint(sum)
What is output by the code below?
sum = 0
for t in range(2, 6):
sum += t
print(sum)
5 points
5
Question 15
15.
What is output by the code below?for num in range(8, 12): if num // 10 == 1: print(num, end = " " )
What is output by the code below?
for num in range(8, 12):
if num // 10 == 1:
print(num, end = " " )
5 points
5
Question 16
16.
What is output by the code below?for i in range(4): for j in range(3): print(i + j, end = " " )
What is output by the code below?
for i in range(4):
for j in range(3):
print(i + j, end = " " )
5 points
5
Question 17
17.
What is output by the code below?for i in range(2,5): for j in range(3, 6): print(j, end = " " )
What is output by the code below?
for i in range(2,5):
for j in range(3, 6):
print(j, end = " " )
5 points
5
Question 18
18.
What is output by the code below?word = "superhero"for let in word: if let != "h": print(let, end = " " ) else: break
What is output by the code below?
word = "superhero"
for let in word:
if let != "h":
print(let, end = " " )
else:
break
5 points
5
Question 19
19.
What is output by the code below?j = 2word = "music notes"for let in word: if j % 2 == 0: print(let, end = " " ) else: print(j, end = " " ) j = j + 1
What is output by the code below?
j = 2
word = "music notes"
for let in word:
if j % 2 == 0:
print(let, end = " " )
else:
print(j, end = " " )
j = j + 1
5 points
5
Question 20
20.
What is output by the code below?s = 0while s = 10: s = s + 4print(s)
What is output by the code below?
s = 0
while s = 10:
s = s + 4
print(s)
1 point
1
Question 21
21.
What is output by the code below?hour = 8if hour > 12: print(hour-12, "O'Clock")else: print(hour, "O'Clock")
What is output by the code below?
hour = 8
if hour > 12:
print(hour-12, "O'Clock")
else:
print(hour, "O'Clock")
1 point
1
Question 22
22.
What is output by the code below?score = 200highScore = 190if score > highScore: print("You beat the high score by", score-highScore, "points!")else: print("You needed", highScore - score, "points")
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")
1 point
1
Question 23
23.
What is output by the code below?numCards = 2if numCards < 2: print("Uno!")else: print("Keep Playing")
What is output by the code below?
numCards = 2
if numCards < 2:
print("Uno!")
else:
print("Keep Playing")
1 point
1
Question 24
24.
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"
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"
1 point
1
Question 25
25.
Consider the incomplete class shown below. The method addScore adds points to score if life is positive.def addScore(points): /* blank */ score += pointsWhich 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):
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):
1 point
1
Question 26
26.
What is output by the code below?x = 5if (x%2==0): print("No Remainder")else: print("Remainder of One")
What is output by the code below?
x = 5
if (x%2==0):
print("No Remainder")
else:
print("Remainder of One")
1 point
1
Question 27
27.
What is output by the code below?note = 2if note == 1: print("Quarter note")elif note == 2: print("Half note")elif note == 4: print("Whole note")
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")
1 point
1
Question 28
28.
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")
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")
1 point
1
Question 29
29.
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")
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")
1 point
1
Question 30
30.
What is output by the code below?numPens = 3if numPens < 2: print("I don't have any extras") else: print("Yes, you can borrow one")
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")
1 point
1
Question 31
31.
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")
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")
1 point
1
Question 32
32.
What is output by the code below?light = "red"if light == "green": print("Drive")else: print("Stop")
What is output by the code below?
light = "red"
if light == "green":
print("Drive")
else:
print("Stop")
1 point
1
Question 33
33.
What is output by the code below?if 3 < 2: print("Less Than")else: print("Greater Than")
What is output by the code below?
if 3 < 2:
print("Less Than")
else:
print("Greater Than")
1 point
1
Question 34
34.
What is output by the code below?lvl = 6if 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")
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")
1 point
1
Question 35
35.
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)
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)
1 point
1
Question 36
36.
What is output by the code below?print("left" == "right" and False == False)
What is output by the code below?
print("left" == "right" and False == False)
1 point
1
Question 37
37.
What is output by the code below?answer = "cup"if answer != "yes": print("Game Over")else: print("Game Start")
What is output by the code below?
answer = "cup"
if answer != "yes":
print("Game Over")
else:
print("Game Start")
1 point
1
Question 38
38.
What is output by the code below?x = 65print(x < 30 or x < 90)
What is output by the code below?
x = 65
print(x < 30 or x < 90)
1 point
1
Question 39
39.
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
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
1 point
1
Question 40
40.
What is output by the code below?gradeLvl = 9if gradeLvl > 8: print("High School")if gradeLvl > 5: print("Middle school")else: print("Elementary school")
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")
1 point
1
Question 41
41.
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")
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 point
1
Question 42
42.
What is output by the code below?x = 200width = 3.2print("Moving Right")if x * width > 800: print("Hit Edge")
What is output by the code below?
x = 200
width = 3.2
print("Moving Right")
if x * width > 800:
print("Hit Edge")
1 point
1
Question 43
43.
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!")
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!")
1 point
1
Question 44
44.
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)
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)
1 point
1
Question 45
45.
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 evendef isOdd(num): /* blank */ return True return False
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
1 point
1
Question 46
46.
What is output by the code below?greaterThan = 15 > 10print(greaterThan)
What is output by the code below?
greaterThan = 15 > 10
print(greaterThan)
1 point
1
Question 47
47.
What is returned by the call makeCookies("yes") ?def makeCookies(answer): if answer == "yes": return True else: return False
What is returned by the call makeCookies("yes") ?
def makeCookies(answer):
if answer == "yes":
return True
else:
return False
1 point
1
Question 48
48.
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")
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")
1 point
1
Question 49
49.
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")
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")
1 point
1
Question 50
50.
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")
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")
1 point
1
Question 51
51.
What is output by the code below?batteryLife = 25if 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")
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")
1 point
1
Question 52
52.
What is output by the code below?y = 11if(y == 21): print("Black Jack")print("Game Finished")
What is output by the code below?
y = 11
if(y == 21):
print("Black Jack")
print("Game Finished")
1 point
1
Question 53
53.
What is output by the code below?month = 11if month == 3: print("Spring Break")elif month == 11: print("Thanksgiving Break")elif month == 12: print("Winter Break")else: print("No big break")
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")
1 point
1
Question 54
54.
What is output by the code below?eggs = Falseif eggs: print("We need eggs")else: print("Start baking")
What is output by the code below?
eggs = False
if eggs:
print("We need eggs")
else:
print("Start baking")
1 point
1
Question 55
55.
What is output by the code below?temp = 33if temp >=212: print("Boiling")elif temp <= 32: print("Freezing")
What is output by the code below?
temp = 33
if temp >=212:
print("Boiling")
elif temp <= 32:
print("Freezing")
1 point
1
Question 56
56.
What is output by the code below?print("cat" == "dog")
What is output by the code below?
print("cat" == "dog")
1 point
1
Question 57
57.
What is output by the code below?pie = "apple"print("Shopping List \neggs \nflour")if pie == "cherry": print("cherries")
What is output by the code below?
pie = "apple"
print("Shopping List \neggs \nflour")
if pie == "cherry":
print("cherries")
1 point
1
Question 58
58.
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)
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)
1 point
1
Question 59
59.
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")
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")
1 point
1
Question 60
60.
What is the output?print ("Chocolate Chip \nCookies”)
What is the output?
print ("Chocolate Chip \nCookies”)
1 point
1
Question 61
61.
What is the output?print (2**2 * 5)
What is the output?
print (2**2 * 5)
1 point
1
Question 62
62.
What is the output?name = "Sally"num = 5print ("Tell", name, "that it is", num)
What is the output?
name = "Sally"
num = 5
print ("Tell", name, "that it is", num)
1 point
1
Question 63
63.
What is the output?def area(length, width, height): return length * width * heightprint (area(3,4,5))
What is the output?
def area(length, width, height):
return length * width * height
print (area(3,4,5))
1 point
1
Question 64
64.
What is the output?class song: def __init__(self, name):
self.name = name def play(self): print ("Playing", self.name)mySong = song("ABC's")mySong.play()
What is the output?
class song:
def __init__(self, name):
self.name = name
def play(self):
print ("Playing", self.name)
mySong = song("ABC's")
mySong.play()
1 point
1
Question 65
65.
What is output by the code below?def area(width,length): return width * length
print(area(2,2))
What is output by the code below?
def area(width,length):
return width * length
print(area(2,2))
1 point
1
Question 66
66.
What is output by the code below?def area(width,length): return width * length
print(area(6,5))
What is output by the code below?
def area(width,length):
return width * length
print(area(6,5))
1 point
1
Question 67
67.
What is output by the code below?def double(word): print(word, word)
double("aplus")
What is output by the code below?
def double(word):
print(word, word)
double("aplus")
1 point
1
Question 68
68.
What is output by the code below?def tripleIt(word): print(word, word, word)
tripleIt("tree")
What is output by the code below?
def tripleIt(word):
print(word, word, word)
tripleIt("tree")
1 point
1
Question 69
69.
What is output by the code below?def driving(vehicle): print("You are driving a", vehicle)
driving("van")
What is output by the code below?
def driving(vehicle):
print("You are driving a", vehicle)
driving("van")
1 point
1
Question 70
70.
What is output by the code below?def volume(width, length, height): return width * length * height
print(volume(2,2,2))
What is output by the code below?
def volume(width, length, height):
return width * length * height
print(volume(2,2,2))
1 point
1
Question 71
71.
What is output by the code below?def volume(width, length, height): return width * length * height
print(volume(2,3,4))
What is output by the code below?
def volume(width, length, height):
return width * length * height
print(volume(2,3,4))
1 point
1
Question 72
72.
What is output by the code below?def singing(song): print("They are singing",) print(song)
singing("Twinkle Twinkle Little Star")
What is output by the code below?
def singing(song):
print("They are singing",)
print(song)
singing("Twinkle Twinkle Little Star")
1 point
1
Question 73
73.
What is output by the code below?def slope(deltaX, deltaY): return deltaY/deltaX
print(slope(4,8.0))
What is output by the code below?
def slope(deltaX, deltaY):
return deltaY/deltaX
print(slope(4,8.0))
1 point
1
Question 74
74.
What is output by the code below?def sayStuff(): print("Hello")print("World")
sayStuff()
What is output by the code below?
def sayStuff():
print("Hello")
print("World")
sayStuff()
1 point
1
Question 75
75.
What is output by the code below?def square(num): return num * num
x = 5print(square(x))
What is output by the code below?
def square(num):
return num * num
x = 5
print(square(x))
1 point
1
Question 76
76.
What is output by the code below?def square(num): return num * num
x = 8print(square(5))
What is output by the code below?
def square(num):
return num * num
x = 8
print(square(5))
1 point
1
Question 77
77.
What is output by the code below?def go(x): return x + x
x = 8print( go(x) )
What is output by the code below?
def go(x):
return x + x
x = 8
print( go(x) )
1 point
1
Question 78
78.
What is output by the code below?def go(x): x = 16
x = 8go( x )print( x )
What is output by the code below?
def go(x):
x = 16
x = 8
go( x )
print( x )
1 point
1
Question 79
79.
What is output by the code below?def go(x): x = 16 print( x )
x = 8go( x )
What is output by the code below?
def go(x):
x = 16
print( x )
x = 8
go( x )
1 point
1
Question 80
80.
What is output by the code below?def product(x, y, z): print("The product of the numbers is", x * z)
product(2,3,5)
What is output by the code below?
def product(x, y, z):
print("The product of the numbers is", x * z)
product(2,3,5)
1 point
1
Question 81
81.
What is output by the code below?def numbers(a, b, c, d): print(a / b + c * d)
numbers(2.0,4,3,5)
What is output by the code below?
def numbers(a, b, c, d):
print(a / b + c * d)
numbers(2.0,4,3,5)
1 point
1
Question 82
82.
What is output by the following code?def getChange(cost, paid): print(paid - cost)
pd = 5.00pr = 2.35getChange(pd, pr)
What is output by the following code?
def getChange(cost, paid):
print(paid - cost)
pd = 5.00
pr = 2.35
getChange(pd, pr)
1 point
1
Question 83
83.
What is output by the following code?def getChange(cost, paid): print(paid - cost)
pd = 5.00pr = 2.35getChange(pr, pd)
What is output by the following code?
def getChange(cost, paid):
print(paid - cost)
pd = 5.00
pr = 2.35
getChange(pr, pd)
1 point
1
Question 84
84.
What is output by the following code?def getChange(cost, paid): print(paid - cost)
pd = 5.00pr = 2.35getChange(pr, pr)
What is output by the following code?
def getChange(cost, paid):
print(paid - cost)
pd = 5.00
pr = 2.35
getChange(pr, pr)