# CMU 15-112 Spring 2019: Fundamentals of Programming and Computer Science Lab 2 (Due as part of hw2 on Sunday 27-Jan, at 5pm)

• Reminder: Lab problems must be solved collaboratively with at least one other student. List your collaborators!
• Do not complete these problems before your scheduled lab on Friday; we'll just make you work on them again with another student, or you won't get the lab attendance credit.

• You should put the solutions to these problems in your hw2.py file. Follow these steps if you haven't started yet!:
1. Create a folder named 'week2'
3. Edit hw2.py using Pyzo
• Do not use string/list indexing, lists/dictionaries, or recursion this week.
• Do not hardcode the test cases in your solutions.
• Your hw2 file should contain answers to these problems (20pts) plus the hw2 problems released earlier this week (80pts)

Collaborative lab problems

1. Lab participation [5pts]
You must attend your Friday lab session and work with at least one other student on the collaborative problems below. You must fill out the attendance form on time to receive these points.

2. COLLABORATIVE Code Writing: drawFlagOfCuba(canvas, width, height) [7pts] [manually-graded]
Note: because of the way the autograder works, this function is stored midway through the starter file, under "Hw2 Graphics Functions". Don't move it above that line!

Write the function drawFlagOfCuba(canvas, width, height) which draws the Flag of Cuba on the given canvas. Well, sort of- you should draw a circle instead of a star, since it will be much easier to draw stars once we learn about lists. You are guaranteed that the proportions of the width and height will be correct (so the width will be twice the size of the height). As is usual with graphics, your image does not need to be pixel-perfect identical to ours, but should be fairly similar. Here's a few flags of different proportions:

drawFlagOfCuba(canvas, 580, 290)

drawFlagOfCuba(canvas, 100, 50)

drawFlagOfCuba(canvas, 300, 150)

Hint: if you want to get the same colors we used, you should use "darkblue", "white", and "red3".

3. COLLABORATIVE Code Writing: isSmithNumber(n) [8pts]
Write the function isSmithNumber(n), which takes a positive integer and returns True if the integer is a Smith number, and False otherwise. A Smith number is a composite (non-prime) number where the sum of its digits is the same as the sum of the digits of its prime factorization, excluding 1. For example, 22 is a Smith number because its prime factors are 2 and 11, and 2 + 2 == 2 + 1 + 1.

Note that in a prime factorization, if a prime can divide a number multiple times, that prime is included multiple times. For example, the prime factorization of 378 is 2 * 3 * 3 * 3 * 7; we can tell 378 is a Smith number because 3 + 7 + 8 = 2 + 3 + 3 + 3 + 7. Likewise, 4 equals 2 * 2, so the prime factor 2 is counted twice, thus making 4 a Smith Number.

Hint: you'll probably want to write a helper function that returns the sum of a number's digits!

4. If you finish early, consider working on the collaborative problem drawThreadPattern from hw2.