Create Performance Task - FINAL
Create Performance Task - FINAL
1. import random
2. import math
3. width = get_width()
4. height = get_height()
5. pink = '#ed4b82'
6. def add_text(x, y, color, font, text):
7. txt = Text(text)
8. txt.set_position(x, y)
9. txt.set_color(color)
10. txt.set_font(font)
11. add(txt)
12. def draw_circle(x, y, radius, color):
13. circ = Circle(radius)
14. circ.set_position(x, y)
15. circ.set_color(color)
16. add(circ)
17. def draw_rectangle(x, y, width, height, color):
18. rect = Rectangle(width, height)
19. rect.set_position(x, y)
20. rect.set_color(color)
21. add(rect)
22. #The 2 functions below come from my graded work in
23. #Codehs assignment 15.1.6. These are not my main function.
24. def draw_happy_pig(x, y):
25. draw_circle(x, y, 50, pink)
26. draw_circle(x + 60, y - 60, 35, pink)
27. draw_rectangle(x - 30, y + 30, 8, 40, pink)
28. draw_rectangle(x - 20, y + 30, 8, 40, pink)
29. draw_rectangle(x + 30, y + 30, 8, 40, pink)
30. draw_rectangle(x + 10, y + 30, 8, 40, pink)
31. draw_circle(x + 70, y - 70, 5, Color.black)
32. draw_circle(x + 50, y - 70, 5, Color.black)
33. draw_circle(x + 60, y - 50, 15, Color.black)
34. draw_rectangle(x + 40, y - 65, 35, 15, pink)
35. draw_circle(x + 30, y - 85, 15, pink)
36. draw_circle(x + 90, y - 85, 15, pink)
37. draw_circle(x - 60, y, 15, pink)
38. def draw_wretched_pig(x, y):
39. draw_circle(x, y, 50, pink)
40. draw_circle(x + 60, y - 60, 35, Color.purple)
41. draw_rectangle(x - 30, y + 30, 8, 40, pink)
42. draw_rectangle(x - 20, y + 30, 8, 40, pink)
43. draw_rectangle(x + 30, y - 70, 8, 40, pink)
44. draw_rectangle(x + 10, y - 80, 8, 40, pink)
45. draw_circle(x + 70, y - 70, 10, Color.red)
46. draw_circle(x + 50, y - 70, 10, Color.red)
47. draw_circle(x + 60, y - 50, 15, Color.black)
48. draw_circle(x + 30, y - 85, 15, pink)
49. draw_circle(x + 90, y - 85, 15, pink)
50. draw_circle(x - 60, y, 15, pink)
51. #Now it is new original code
52. def write_6line_text(y, a, b, c, d, e, f):
https://codehs.com/editor/print_assignment_code/144910737/5491323?noname§ion_id=573528 1/7
4/25/25, 12:55 PM Create Performance Task | CodeHS
53. add_text(10, y, Color.black, "11pt Arial", a)
54. add_text(10, y+25, Color.black, "11pt Arial", b)
55. add_text(10, y+50, Color.black, "11pt Arial", c)
56. add_text(10, y+75, Color.black, "11pt Arial", d)
57. add_text(10, y+100, Color.black, "11pt Arial", e)
58. add_text(10, y+125, Color.black, "11pt Arial", f)
59. def draw_boxed_text(x, y, a, b, c, d, e, f):
60. draw_rectangle(x, y, 220, 150, Color.black)
61. draw_rectangle(x+2, y+2, 216, 146, Color.white)
62. add_text(x+3, y+30, Color.black, "9pt Arial", a)
63. add_text(x+4, y+50, Color.black, "9pt Arial", b)
64. add_text(x+4, y+70, Color.black, "9pt Arial", c)
65. add_text(x+4, y+90, Color.black, "9pt Arial", d)
66. add_text(x+4, y+110, Color.black, "9pt Arial", e)
67. add_text(x+4, y+130, Color.black, "9pt Arial", f)
68. def draw_scene1():
69. remove_all()
70. write_6line_text(100, "Let's start with a review of Arithmetic Sequences.", "You know an arithmet
71. draw_happy_pig(50, 400)
72. draw_boxed_text(180, 250, "Bob says: Remember that the arithmetic", "mean formula: An =
(A_(n+1)+A_(n-1))/2", "Also, you can write an arithmetic series", "as ...a-2d, a, a+d, a+2d...",
"Oink Oink!", "Please click to continue to Method 1")
73. def draw_scene2():
74. remove_all()
75. add_text(20, 100, Color.red, "14pt Arial", "1: Arithmetic Sequences")
76. write_6line_text(120, "You can write an arithmetic sequence as", "a, a+d, a+2d,...", "and you
know the sum of an arithmetic sequence.", "Most problems will use straightforward", "application
of these formulas. Let's try an example", "which only requires knowledge of the formulas.")
77. write_6line_text(295, "EXAMPLE: Original Problem", "An arithmetic progression with 1st term
5", "and >2 positive integer terms has sum 539.", "What is the value of the 3rd term?", "Please
click to answer.", "After answering, please click to continue.")
78. def draw_scene3():
79. hint_list_1 = ["", "Remember: the sum of the terms in this arithmetic sequence is n(2*5+(n-
1)d)/2 = 539.", "The prime factorization of 1078 is 2*7^2*11.", "The third term is 5 + 2d."]
80. user_solution1 = 0
81. while user_solution1 <4:
82. user_input = int(input("What is the answer? " + hint_list_1[user_solution1]))
83. if user_input == 53:
84. print("Good job! Compare your solution to the solution below to see if you could've
done it a different way.")
85. break
86. else:
87. user_solution1 += 1
88. print("SOLUTION: Write the sum as n(2*5 + (n-1)d)/2 = 539. Thus, you know n(2*5 + (n-1)d) =
1078 and n is a divisor of 1078. Prime factorize 1078 to get 2*7^2*11. d = (1078 - 10n)/(n(n-1)).
Try values of n greater than 2 to find that n = 7, d = 24 works and no other value of n fulfills
the conditions of the problem. The third term is 5 + 2*d = 5 + 2*24 = 53.")
89. def draw_scene4():
90. remove_all()
91. add_text(20, 100, Color.red, "14pt Arial", "2: Geometric Sequences")
92. write_6line_text(120, "Geometric sequences are similar to arithmetic sequences.", "They can
be written as a, ar, ar^2, ar^3...", "and the sum of a diverging geometric sequence (r>1)", "is
A_1(r^n-1)/(r-1).", "However, when 0<r<1 the sum equals A_1/(1-r).", "This is called a converging
sequence.")
93. write_6line_text(295, "Worked out example: Classic Problem", "What is the sum of S = 1/2 +
2/4 + 3/8... to infinity?", "S/2 = 1/4 + 2/8 + 3/16... so S - S/2 = 1/2 + 1/4 + 1/8...", "This
converges. Thus, S/2 = (1/2)/(1 - 1/2) = 1", "S = 2 Bob thinks this is a cool problem.", "Please
click to play 'Odds or Evens' with Bob!")
94. def odds_or_evens_intro():
95. add_text(20, 100, Color.red, "20pt Arial", "Odds or Evens")
96. add_text(10, 120, Color.green, "10pt Arial", "4 Questions. Winner gets 1 point. Correct
answer = 1 point.")
97. add_text(10, 140, Color.green, "11pt Arial", "2 or more correct in a row = 2 points.")
98. def draw_scene5():
99. remove_all()
100. add_text(20, 100, Color.red, "20pt Arial", "Odds or Evens")
https://codehs.com/editor/print_assignment_code/144910737/5491323?noname§ion_id=573528 2/7
4/25/25, 12:55 PM Create Performance Task | CodeHS
101. write_6line_text(120, "You play vs Bob. Both of you will enter a number.", "Decide if the sum
of the numbers is even or odd.", "Every turn, you and Bob switch.", "If you're right, you get 1
pt. Then, solve a problem.", "If you're right, you get one point.", "If you have a winning
streak, you get 2 pts.")
102. add_text(20, 300, Color.blue, "12pt Arial", "There are 4 questions. Try to beat Bob!")
103. def draw_scene6():
104. remove_all()
105. odds_or_evens_intro()
106. global prob_level
107. prob_level = input("What level of difficulty would you like your problems to be: BASIC or
ADVANCED?")
108. your_score = 0
109. bob_score = 0
110. problems_correct = ["I"]
111. def game_scoring():
112. global your_score
113. global bob_score
114. user_number = int(input("Bob has chosen his number. Please enter your number: "))
115. even_or_odd = input("It's your turn. Do you think the sum of your number and Bob's number is
EVEN or ODD? Please type 'EVEN' or 'ODD': ")
116. bob_num = random.randint(1, 50)
117. if (((user_number + bob_num) % 2 == 0) and (even_or_odd == "EVEN")) or (((user_number +
bob_num) % 2 == 1) and (even_or_odd == "ODD")):
118. print("Your number was " + str(user_number) + " and Bob's number was " + str(bob_num) +
". You thought the sum of the two numbers was " + even_or_odd + " and you were right! You get 1
point.")
119. your_score += 1
120. else:
121. print("Your number was " + str(user_number) + " and Bob's number was " + str(bob_num) +
". You thought the sum of the two numbers was " + even_or_odd + " but unfortunately you were
wrong. Bob gets 1 point.")
122. bob_score += 1
123. def bob_turn():
124. global your_score
125. global bob_score
126. user_number = int(input("Bob has chosen his number. It's his turn, so he will decide if he
thinks the sum is even or odd. Please enter your number: "))
127. bob_num = random.randint(1, 50)
128. bob_even_or_odd = random.randint(0, 1)
129. if bob_even_or_odd == 0:
130. even_or_odd2 = "EVEN"
131. else:
132. even_or_odd2 = "ODD"
133. if (((user_number + bob_num) % 2 == 0) and (even_or_odd2 == "EVEN")) or (((user_number +
bob_num) % 2 == 1) and (even_or_odd2 == "ODD")):
134. print("Your number was " + str(user_number) + " and Bob's number was " + str(bob_num) +
". Bob thought the sum of the two numbers was " + even_or_odd2 + " and Bob was right. He gets 1
point.")
135. bob_score += 1
136. else:
137. print("Your number was " + str(user_number) + " and Bob's number was " + str(bob_num) +
". Bob thought the sum of the two numbers was " + even_or_odd2 + " but Bob was wrong. You get 1
point.")
138. your_score += 1
139. def game_scoring_display():
140. add_text(10, 330, Color.blue, "12pt Arial", "The score is " + str(your_score) + " (you) to " + st
141. add_text(10, 350, Color.blue, "12pt Arial", "Click to answer the question & get points!")
142. if your_score <= bob_score:
143. draw_happy_pig(300, 400)
144. else:
145. draw_wretched_pig(300, 400)
146. prob_list = []
147. adv_solutions = [21, 9, 59, 1, 33, 12, 195, 129, 348, 135, 137, 262]
148. num_probs_adv = 12
149. def generate_problem(level):
150. global answer
https://codehs.com/editor/print_assignment_code/144910737/5491323?noname§ion_id=573528 3/7
4/25/25, 12:55 PM Create Performance Task | CodeHS
151. if level == "BASIC":
152. quest_type = random.randint(1, 2)
153. num_1 = random.randint(1, 50)
154. num_2 = random.randint(1, 50)
155. num_3 = random.randint(1, 50)
156. num_4 = random.randint(1, 50)
157. num_5 = random.randint(1, 50)
158. while True:
159. if num_1 == num_3:
160. num_3 = random.randint(1, 50)
161. else:
162. break
163. while True:
164. if num_2 == num_4:
165. num_4 = random.randint(1, 50)
166. else:
167. break
168. while True:
169. if (num_5 == num_1) or (num_5 == num_3):
170. num_5 = random.randint(1, 50)
171. else:
172. break
173. if quest_type == int(1):
174. add_text(15, 200, Color.black, "12pt Arial", "Given that in arithmetic sequence A,
A_" + str(num_1))
175. add_text(15, 225, Color.black, "12pt Arial", "has a value of " + str(num_2) + " and
A_" + str(num_3) + " has a value of " + str(num_4) + ",")
176. add_text(15, 250, Color.black, "12pt Arial", "find the value of " + "A_" + str(num_5)
+ "." + " Click to answer and continue.")
177. d = float((num_4 - num_2)/(num_3 - num_1))
178. A_1 = float(num_2 - (num_1 - 1)*d)
179. answer = float(A_1 + (num_5 - 1)*d)
180. return answer
181. else:
182. add_text(15, 200, Color.black, "12pt Arial", "What is the sum of all the positive
integers")
183. add_text(15, 225, Color.black, "12pt Arial", "in the closed interval [" + str(num_1)
+ ", " + str(num_2) + "]?")
184. add_text(15, 250, Color.black, "12pt Arial", "Click to answer and continue.")
185. answer = float((num_1 + num_2)*(abs(num_1 - num_2)+1)/2)
186. return answer
187. elif level == "ADVANCED":
188. global prob_list
189. global adv_solutions
190. global num_probs_adv
191. #The problems below are taken from various competitions or books, not my original work.
192. AMC10A_2024_19 = ["The first 3 terms of a geometric sequence are the", "integers a, 720,
and b, where a < 720 < b.", "What is the sum of the digits of the least possible ", "value of
b?", "", ""]
193. AMC10A_2016_9 = ["A triangular array of 2016 coins has 1 coin in the", "1st row, 2 coins
in the 2nd row, 3 in the 3rd row,", "and so on up to N coins in the Nth row.", "What is the sum
of the digits of N?", "", ""]
194. AMC10A_2006_19 = ["How many non-similar triangles have angles", "whose degree measures
are distinct positive", "integers in arithmetic progression?", "", "", ""]
195. AMC12A_2009_17 = ["Let a + ar_1 + ar_1^2 + ar_1^3...", "and a + ar_2 + ar_2^2 + ar_2^3 +
... ", "be two different infinite geometric series of positive", "numbers with the same 1st term.
The sum of the 1st", "series is r_1, and the sum of the 2nd series is r_2.", "What is r_1 +
r_2?"]
196. AIME_1986_6 = ["The pages of a book are numbered 1 through n.", "When the page #s of the
book were added,", "one of the page numbers was mistakenly added twice,", "resulting in an
incorrect sum of 1986. What was", "the number of the page that was added twice?", ""]
197. AIME1_2005_2 = ["For each positive integer k, let Sk denote the", "increasing arithmetic
sequence of integers whose", " 1st term is 1 and whose common difference is k. For", "example,
S_3 is the sequence 1, 4, 7, 10,... For how", "many values of k does S_k contain the term 2005?",
""]
https://codehs.com/editor/print_assignment_code/144910737/5491323?noname§ion_id=573528 4/7
4/25/25, 12:55 PM Create Performance Task | CodeHS
198. AIME1_2012_2 = ["The terms of an arithmetic sequence add to 715.", "The first term of the
sequence is increased by 1,", "and in general, the kth term is increased by the", "kth odd
positive integer. The terms of the new", "sequence add to 836. Find the sum of the first,",
"last, and middle terms of the original sequence."]
199. AIME1_2003_8 = ["In an increasing sequence of 4 positive integers,", "the first three
terms form an arithmetic progression,", " the last three terms form a geometric progression,",
"and the first and fourth terms differ by 30.", "Find the sum of the four terms.", ""]
200. AIME2_2003_8 = ["Find the eighth term of the sequence", "1440, 1716, 1848,... whose terms are
201. MPFG_2010_4 = ["Consider the sequence of six real numbers", "60, 10, 100, 150, 30, and x.
The arithmetic mean", " of this sequence is equal to the median.", "What is the sum of all the
possible values of x?", "", ""]
202. AMC10A_2020_21 = ["There exists a unique strictly increasing sequence", "of nonnegative
integers a_1 < a_2 <...< a_k such that", "(2^289 + 1)/(2^17 + 1) = 2^a_1 + 2^a_2 + ... 2^a_k.",
"What is k? NOTE FOR COMPREHENSION: Split it", "into individual different powers of 2 and find
how", "many 2^n there are."]
203. AIME2_2016_9 = ["The sequences of positive integers 1, a2, a3, ... and", "1, b2, b3, ...
are an increasing arithmetic sequence", "and an increasing geometric sequence, respectively.",
"Let cn = an + bn. There is an integer k such that", "c_(k−1) = 100 and c_(k+1) = 1000. Find
c_k.", "NOTE: The only strategy for this problem is bashing."]
204. prob_list.append(AMC10A_2024_19)
205. prob_list.append(AMC10A_2016_9)
206. prob_list.append(AMC10A_2006_19)
207. prob_list.append(AMC12A_2009_17)
208. prob_list.append(AIME_1986_6)
209. prob_list.append(AIME1_2005_2)
210. prob_list.append(AIME1_2012_2)
211. prob_list.append(AIME1_2003_8)
212. prob_list.append(AIME2_2003_8)
213. prob_list.append(MPFG_2010_4)
214. prob_list.append(AMC10A_2020_21)
215. prob_list.append(AIME2_2016_9)
216. adv_num = random.randint(0, int(num_probs_adv-1))
217. write_6line_text(170, prob_list[adv_num][0], prob_list[adv_num][1], prob_list[adv_num]
[2], prob_list[adv_num][3], prob_list[adv_num][4], prob_list[adv_num][5])
218. prob_list.remove(prob_list[adv_num])
219. answer = adv_solutions[adv_num]
220. adv_solutions.remove(adv_solutions[adv_num])
221. num_probs_adv -= 1
222. return answer
223. else:
224. print("The difficulty level you entered isn't valid.")
225. def write_ans(quest_num):
226. global your_score
227. global problems_correct
228. global bob_score
229. #I searched up on Google how to do the floor function in python
230. num_prob = int(input("What is the greatest integer <= the answer? "))
231. if num_prob == int(math.floor(answer)):
232. your_score += 1
233. problems_correct.append("C")
234. if problems_correct[quest_num] == problems_correct[quest_num - 1]:
235. your_score += 1
236. print("Correct! Your score increased by 2 because you have a winning streak!")
237. else:
238. print("Correct! Your score increased by 1.")
239. else:
240. problems_correct.append("I")
241. print("Incorrect! The correct answer was " + str(math.floor(answer)))
242. bob_trick_num = random.randint(1, 10)
243. if bob_trick_num <=4:
244. print("Hee hee! Bob secretly added 1 point to his score. There's nothing you can do about
it :(")
245. bob_score += 1
246. if bob_tric_num == 10:
247. print("Hee hee! Bob secretly added 234092 points to his score. There's nothing you can do
about it :(")
https://codehs.com/editor/print_assignment_code/144910737/5491323?noname§ion_id=573528 5/7
4/25/25, 12:55 PM Create Performance Task | CodeHS
248. bob_score += 234092
249. def draw_scene7():
250. game_scoring()
251. def draw_scene8():
252. generate_problem(str(prob_level))
253. game_scoring_display()
254. def draw_scene9():
255. write_ans(1)
256. def draw_scene10():
257. remove_all()
258. odds_or_evens_intro()
259. bob_turn()
260. def draw_scene11():
261. generate_problem(str(prob_level))
262. game_scoring_display()
263. def draw_scene12():
264. write_ans(2)
265. def draw_scene13():
266. remove_all()
267. odds_or_evens_intro()
268. game_scoring()
269. def draw_scene14():
270. generate_problem(str(prob_level))
271. game_scoring_display()
272. def draw_scene15():
273. write_ans(3)
274. def draw_scene16():
275. remove_all()
276. odds_or_evens_intro()
277. bob_turn()
278. def draw_scene17():
279. generate_problem(str(prob_level))
280. game_scoring_display()
281. def draw_scene18():
282. write_ans(4)
283. def draw_scene19():
284. global your_score
285. global bob_score
286. remove_all()
287. draw_rectangle(0, 0, get_width(), get_height(), Color.blue)
288. if your_score > bob_score:
289. add_text(10, 200, Color.red, "40pt Arial", "You won!")
290. elif your_score == bob_score:
291. add_text(10, 200, Color.red, "40pt Arial", "You tied!")
292. else:
293. add_text(10, 200, Color.red, "40pt Arial", "You lost!")
294. add_text(15, 250, Color.black, "12pt Arial", "Bob hopes you are better at sequence problems
now!")
295. draw_happy_pig(300, 360)
296. draw_rectangle(0, 3*get_height()/4, get_width(), get_height()/4, Color.green)
297. draw_rectangle(5, 3*get_height()/4 + 5, get_width() - 10, get_height()/4 - 10, Color.white)
298. add_text(20, 400, Color.red, "20pt Arial", "Click on this button to")
299. add_text(20, 440, Color.red, "20pt Arial", "play Odds and Evens again!")
300.
301. add_text(20, 100, Color.red, "20pt Arial", "Learn Sequences and Series")
302. add_text(15, 150, Color.green, "12pt Arial", "This is an interactive course to improve your")
303. add_text(15, 200, Color.green, "12pt Arial", "knowledge of advanced sequences and series. Learn")
304. add_text(15, 250, Color.green, "12pt Arial", "through the help of Bob, the Friendly Math Pig!")
305. add_text(20, 350, Color.red, "20pt Arial", "Click to Start!")
306. draw_happy_pig(300, 360)
307.
308.
309. #Most of the code below is from Codehs assignment 15.1.6
310. scene_counter = 0
311.
312. def draw_next_screen(x, y):
https://codehs.com/editor/print_assignment_code/144910737/5491323?noname§ion_id=573528 6/7
4/25/25, 12:55 PM Create Performance Task | CodeHS
313. global scene_counter
314. scene_counter += 1
315. #This is my code
316. global your_score
317. global bob_score
318. global problems_correct
319. #Now it is code from Codehs assignment 15.1.6
320. if scene_counter == 1:
321. draw_scene1()
322. elif scene_counter == 2:
323. draw_scene2()
324. elif scene_counter == 3:
325. draw_scene3()
326. elif scene_counter == 4:
327. draw_scene4()
328. elif scene_counter == 5:
329. draw_scene5()
330. elif scene_counter == 6:
331. draw_scene6()
332. elif scene_counter == 7:
333. draw_scene7()
334. elif scene_counter == 8:
335. draw_scene8()
336. elif scene_counter == 9:
337. draw_scene9()
338. elif scene_counter == 10:
339. draw_scene10()
340. elif scene_counter == 11:
341. draw_scene11()
342. elif scene_counter == 12:
343. draw_scene12()
344. elif scene_counter == 13:
345. draw_scene13()
346. elif scene_counter == 14:
347. draw_scene14()
348. elif scene_counter == 15:
349. draw_scene15()
350. elif scene_counter == 16:
351. draw_scene16()
352. elif scene_counter == 17:
353. draw_scene17()
354. elif scene_counter == 18:
355. draw_scene18()
356. else:
357. #This is my own code
358. if y >= 3*get_height()/4:
359. your_score = 0
360. bob_score = 0
361. problems_correct = ["I"]
362. remove_all()
363. scene_counter = 6
364. else:
365. draw_scene19()
366. #Now it is Codehs 15.1.6 code
367.
368. add_mouse_click_handler(draw_next_screen)
https://codehs.com/editor/print_assignment_code/144910737/5491323?noname§ion_id=573528 7/7