Here are some problems for you to try. Use them for quiz and exam preparation. Some are old assessments, some were originally written by grade 11 students in my Java course. Julian D. rewrote them in Python for you!
This style of question will be on the first half of the exam. To prepare for the second half, review the exam page.
#ICS3U Python Assessment 1
#
#
#NAME:_________________________
#Provide all output.
pearl = False
jam = True
x = 10
y = 15
print(pearl)
print(jam)
if(pearl == True):
print(x)
else:
print(y)
pearl = jam
if(pearl == True):
print(-x)
else:
print(-y)
if(jam != pearl):
x = 1
elif(pearl != jam):
x = 2
else:
jam = True
print(jam)
print(x)
#ICS3U Python Assessment 2
#
#
#NAME:_________________________
#Provide all output.
q = 0
r = 0
#print(q)
flag = False
for x in range(0, 5):
flag = False
print(x)
flag = True
print(flag)
while q <= 3:
print('A')
print(q)
q+=1
while(q <= 3):
print('B')
print(q)
q+=1
while flag == False:
print(flag)
flag = True
print('hip')
while flag == True:
print(flag)
flag = False
print('hop')
#ICS3U Python Assessment 2v2
#
#
#NAME:_________________________
#Provide all output.
q = 0
r = 0
#print(q)
flag = False
for x in range(0, 5):
flag = True
print(x)
flag = False
print(flag)
while q <= 3:
print('A')
print(q)
q+=1
while(q <= 3):
print('B')
print(q)
q+=1
while flag == False:
print(flag)
flag = True
print('hip')
while flag == True:
print(flag)
flag = False
print('hop')
#ICS3U Python Assessment 3
#
#
#NAME:_________________________
#Provide all output.
for dog in range(0,2):
print('OUT')
print(dog)
for cat in range(0,2):
print('In')
print(cat)
#print('DONE')
#ICS3U Python Assessment 3v2
#
#
#NAME:_________________________
#Provide all output.
for dog in range(0,2):
print('OUT')
print(dog)
for cat in range(0,2):
print('In')
print(cat)
#print('DONE')
#ICS3U Python Assessment 4
#
#
#NAME:_________________________
#Provide all output.
for i in range(3):
print(i)
print('swing')
for i in range(3, 0, -1):
print(i)
print('swing')
for i in range(0, 6, 2):
print(i)
#ICS3U Python Assessment 5
#
#
#NAME:_________________________
#Provide all output.
q = 0
flag = False
j = 0
for i in range(0,3):
print('woo '+ str(i))
flag = True
q+=1
print('hoo ' + str(q))
print('boo ' + str(j))
for u in range(q):
print('doo '+ str(u))
if((u % 2 == 0) and (flag == True)):
print('goo ' + str(j))
print('moo ' + str(i))
#ICS3U Python Assessment 6
#
#
#NAME:_________________________
#Provide all output.
def foo():
print('light')
def returnOfTheJedi(x):
return x
def neatO(ii):
ii = ii + 1
return ii
def thisWasNotPartOfThePlan():
haa = 1
foo()
return haa
def baa(ee):
print(ee)
def areYouSure():
return False
def meThinksNot(ff):
ff = True
return False
def doo(xx, yy):
print(yy + xx)
def order66(cc):
padawan = cc - 9999
return padawan
def goo(x):
print(x)
x = '5'
baa('saber')
foo()
goo(x)
goo(5)
returnOfTheJedi('Luke')
jedi = returnOfTheJedi('Luke')
goo(jedi)
doo(jedi, x)
q = thisWasNotPartOfThePlan()
if q == 1:
x = 'bulb'
b = order66(10000)
else:
x = 'box'
b = order66(10001)
goo(x)
goo(b)
for counter in range(1,5):
jj = neatO(counter)
goo(jj)
problems = areYouSure()
print('Is Luke a jedi? ' + str(problems))
problems = meThinksNot(True)
print('Is anyone Luke trains, a jedi? ' + str(problems))
print('How many Jedi are left? ' + str(b))
# Quiz 7
group = [9,8,7,6,5,4,3,2,1]
def foo(x):
print(x)
x[0]=99
l = len(x)
for c in range(l):
print(x[c])
def boo(y):
q = []
s = len(group)
while s > 0:
print(y[s-1])
q.append(y[s-1])
s-=1
print(q)
foo(group)
boo(group)
# Quiz 8
b1 = ['rp','jp','jpj','jb']
b2 = ['jl','pm','rs','gh']
def makeAMess(q, qq):
mess = b1 + b2
print(mess)
def showUgly(w):
print(w)
def showNice(ww):
for x in ww:
print(x)
def moveEm(mm, m):
mm.append(m)
def kick(ee, e):
member = ee.pop(e)
return member
showUgly(b1)
showUgly(b2)
makeAMess(b1,b2)
someone = kick(b1,0)
moveEm(b2, someone)
someone = kick(b2,0)
moveEm(b1, someone)
showUgly(b1)
showUgly(b2)
# Quiz 9
i = ''
iv = ''
v = ''
progression = []
mysong = []
circleOfFifths = ['C','G','D','A','E','B','Gb/F#','Db','Ab','Eb','Bb','F']
def howMany(c, n):
c = c * n #yes, this is ugly (*shudder*) but it works. I am multiplying strings.
return c
progression = circleOfFifths[0:3]
i = progression[1]
iv = progression[0]
v = progression[2]
print(progression)
chords = howMany(i, 4)
mysong.append(chords)
chords = howMany(iv, 2)
mysong.append(chords)
chords = howMany(i, 2)
mysong.append(chords)
chords = howMany(v, 2)
mysong.append(chords)
chords = howMany(iv, 2)
mysong.append(chords)
print(mysong)
#
#test.py
#
a = 'print'
b = 1
x = 3
boo = True
while b < 3:
b += 1
for z in range(x):
print(z)
print('b ' + '= ' + str(b))
if a == 'PRINT':
print('Potato')
boo = False
a = 'MOO'
if a == 'MOO':
print('B')
print(boo)
#
#student_quiz.py
#
s = 'blah'
a = 0
b = 1
c = 3
for x in range(4):
print(x)
print(b)
a = a + x
while c > 0:
c -= 1
print(c)
b = a + c
print(b)
print(s)
for x in range(5, -1, -1):
print(x)
if x == 5:
print(b + x)
elif x== 4:
print('P +' + str(c))
elif x==3:
print('Nothing prints here at all')
elif x==2:
print(a + b + c)
else:
print(str(x + a + b + c) + s)
print('All done now.')
#
#sample_quiz001.py
#
x = 3
y = 5
jah = False
oink = 'moo'
while x > 0:
print('M' + str(x))
x -= 1
y += 1
while jah:
print('We like to party.')
cowArray = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
while y > 0:
print(str(cowArray[y]) + ' cows in the pasture.')
q = 0
while q < y:
print(oink)
y -= 1
q += 1
y -= 1
#
#riddled_walkthrough.py
#
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
alpha = 'abcdefghijklmnopqrstuvwxyz'
guess = ''
answer = 0
count = 0
x = 0
print('Riddle: \nWhat is at the beginning of the end, but at the end of time & space?')
answer = len(alpha)
answer = answer + 1
answer = answer % 2
answer = answer * 6
#answer = 5 ^ answer # ^ is XOR
answer = int(answer / 25)
answer = answer % 5
answer = answer + 4
x = answer
while count < 99:
if count == x:
guess = alphabet[x]
count = 100
else:
count += 1
print('What is your guess? \n' + guess)
print('Is that your final answer?')
if guess == 'E':
print('No')
elif guess == 'E' or guess == 'e':
print('Yes')
else:
print('I do not know')
if guess == 'e':
print('Gz you solved the riddle!')
else:
print('You are still Green! Keep practicing! >;)')
#
#quiz1.py
#
x = 4
y = 2
z = 1
names = ['Bob', 'Bill', 'Joe', 'Moe', 'Hank']
print(x)
print(y)
z += 1
x = y - z
print(x)
for count in range(5):
print(count)
y += 1
print(y)
print(names[0])
print(names[2])
print(names[4])
if y == x:
names[1] = 'Jim'
else:
names[0] = 'George'
print(names[0])
print(names[1])
print(names[2])
print(names[3])
print(names[4])
print(y)
#
#quiz_sand_g.py
#
a = 0
b = 1
c = 2
d = 3
boo = 'b'
flag = True
print('One: ' + str(b), end = '')
print(' Two: ' + str(c), end = '')
print(' Three: ' + str(d), end = '')
print()
print(boo)
if flag == False:
print(boo)
print(boo)
if flag != False:
a = c + d
print(a)
for foo in range(d):
print('You')
for woo in range(2):
print('Rock')
while flag != False:
a = a + a
print(a)
print(boo)
flag = False
while c > 0:
print('Good')
for moo in range(2, 0, -1):
print('Luck')
c -= 1
#
#quiz.py
#
x = 0.0
y = 0
a = 0
a += 1
x += 1
z = 6
d = z - a
blah = 'bob'
flag = False
print('x')
george = []
for q in range(z):
george.append(0)
for p in range(d):
george[a] = p
a += 1
flag = True
while flag:
print(blah + str(a))
flag = False
print(george[y])
george[y] += 1
print(george[y])
y += 1
print(y)
print(x)
x -= 1
print('[', end = '')
for p in range(z):
print(george[p], end = '')
if d > p:
print(',', end = '')
print(']')
#
#python_array_quiz.py
#
lantern = [False, False, False]
hextech = 0
piano = 0
violin = 0
while piano < 2:
piano += 1 #
print('piano')
while hextech < 3:
print(hextech)
hextech += 1
print(piano, end = '')
while violin < 2:
if piano < 3:
lantern[violin] = True
else:
lantern[violin] = False
print(lantern[violin])
violin += 1
piano += 1
while hextech > 0:
print('^cake')
hextech -= 1
hextech += 1
print('This is the 12th line printed.')
#
#exam_printactice_test.py
#
x = 0
y = 0
z = 0
n = True
s = 'Hi'
print (y)
for w in range(5):
print (w)
y += 1
print (y)
while n == True:
if x == 0:
print (s)
x += 1
#print (x)
if z < 4:
z += 1
print (z)
if z == 4:
n = False
print (s)
#
#evil_quiz.py
#
apple = [1, 2, 3, 4, 6, 9, 54]
pear = 0
peach = 2
orange = ''
banana = '!'
celery = ['Yes.', 'NO', 'No!', 'no', 'OK', 'fun']
cheese = False
bread = True
print('banana', end = '')
print(banana)
for counter_1 in range(0, 5, 2):
print(str(apple[counter_1]) + orange)
counter_1 += 1
print(peach)
peach += 1
print(peach)
print('This is where the fun starts')
if cheese != False:
print('Or is it?')
for counter_2 in range(-5, 2, -1):
print(counter_2)
#print(counter_2)
else:
print('Yes, yes it is ' + str(apple[5]))
for counter_3 in range (4, -1, -1):
print(celery[counter_3])
if counter_3 == 0:
bread = False
else:
print('Is it ' + celery[5] + ' yet?')
print('celery[2]')
if celery[5] == 'FUN':
print(cheese)
else:
print('I probably failed this quiz')
#
#course_quiz.py
#
hipster = 'mainstream'
you = ''
counter = 0
countar = 0
kewl = 20
snoopdawg = 98357
einstein = [150, 93, 15, 12, 6]
you = 'you'
for countah in range(5):
print(einstein[countah])
#print('yourmom')
for count in range(5):
while counter < 100:
print(str(count) + ',', end = '')
counter = counter + 10
countar = count
#snoopdawg = 5
print('\nHipterz r so' + hipster, end = '')
counter = 90
while snoopdawg == 98357:
snoopdawg = int(kewl / 2)
snoopdawg = kewl + countar
print('\n' + str(snoopdawg))
hipster = 'dog'
snoopdawg += 1
print('hipster')
print(you)
#
#bird_loop.py
#
counter = 0
num = 0
test = [1, 3, 5, 7, 2, 6, 1, 0]
for count in range(5):
while counter < 100:
print(str(count) + ',', end = '')
counter = counter + 10
print (str(counter) + (' ? '))
counter = 0
for count in range(20):
print (test[num])
num = (test[num])
print(num, end = '')
#
#beat_box_test.py
#
a = 0
b = 0
boo = True
awesomeArray = ['ch', 'Whap', 'Bmph', 'Whicka', 'Bap', 'ah', 'waw', 'duduh', 'neeo']
x = 8
while x > a:
a += 2
print(awesomeArray[a])
print(awesomeArray[x])
x -= 1
y = 3
while y < 0:
y -= 1
print(awesomeArray[0])
for z in range(20, 21, -1):
print(awesomeArray[1])
x -= 1
for z in range(1, 4):
print(awesomeArray[4])
#
#barn_animal_test.py
#
pig = 'cow'
cow = 'chicken'
chicken = 'farmer'
farmer = 'pig'
barnYard = []
for i in range(100):
barnYard.append('')
for set1 in range(99, 0, -1):
barnYard[set1] = 'null'
print('Welcome to the barnyard')
if farmer == 'PIG' or farmer == 'pig':
print(pig)
if farmer == 'PIG':
print(cow)
if farmer == 'PIG' or farmer == 'pig':
print(farmer)
if farmer == 'PIG ' or farmer == 'pig ':
print(chicken)
for x in range(10, 11):
barnYard[37] = 'corn'
farmer = 'farmerJoe'
chicken = 'leanardo'
cow = 'frank'
pig = 'piggy'
barnYard[96] = 'birth of a platypus'
print('farmer name is' + ': ' + farmer + '\nand the chicken is nammed' + ' :' + ' ' + chicken + '.\n', end = '')
for water in range(0, -3, -1):
print(water)
for grass in range(3):
print('Grass')
for hay in range(1, 0, -1):
print(barnYard[5])
print('\nDont eat my chickens wings')
x = 99
while x > 20:
barnYard[x] = 'harvest'
x = x - 10
print('barnYard @ 49 = ' + barnYard[39])