2014-03-31 + HW

posted Mar 31, 2014, 5:32 AM by Samuel Konstantinovich   [ updated Mar 31, 2014, 10:39 AM ]

Homework: Problems 7,9,10

AP Computer Science: If you are interested in computer science you should apply for the AP course.

*Counts for 10-tech/AppliedScience credit.

Regarding other AP's, and other classes:

*You should not prioritize a class that someone tells you 'looks better' for colleges because it probably doesn't.

*If you complete all three years of the CS classes here, you will be prepared for a real job and over prepared for college CS. You will be trained to work in groups on real projects. (demo)

*If you love computer science, you should apply now. It is a popular class with more students than seats. The priority students are accepted are as follows:

*Juniors that applied as a sophomore but did not get accepted get 1st priority.

*Sophomores that apply get 2nd priority. (This is you right now)

*Juniors that did not apply as sophomores get last priority... so they don't get into it.

Conclusion: If you do not apply now, you can not take it.

Goal: Practice with Loops:

*While you work on this lab, have your HW out.


Random Numbers and lists lab: name your file : randomListLab.py

use the command:

   import random

Then experiment with:



Answer these as comments in your lab:

1.How do you use these functions? (explain as if you are talking to a noob)

2.How could you create a random integer between 5 and 10?

3. How could you create a random floating point (real number) between 4.35 and 10.35?

You shoud think about a function makeRandomList(...) to create a list of random integers.

BEFORE writing it:

Think about what would be useful parameters to this function:

4.What do you think is(are) the minimum number useful parameter(s)?

5. What are good optional parameters?

6. Comment the top of your random list maker function what your parameters are for.

7. Write the function

You can then use this function to create random lists to feed into other functions!!!


Try to use both of your barGraph() functions on a random lists. Make a loop that prints 10 bar graphs on random lists. (BOTH horizontal and vertical graphs)

#problems 9 onward have been added to help you practice problem solving / algorithm writing:

9. Write a function matching() that compares two lists, it should return the number of corresponding elements that match. If one list is longer than the other, only compare up to the shorter list's last element. 

matching([1,2,3],[2,3,4]) returns 0

matching([1,2,3],[2,2,3]) returns 2

matching([4,1,9,2,3],[2,1,9,2,3,3,3,3]) returns 4

10. Write a function stringToList() that takes a string and returns a list of the characters from that string. (Do not use the built in string method that accomplishes this): (if you used a for loop in #10, then use a while loop, and vice versa)

stringToList("bob") returns ['b','o','b']

stringToList("Hoooot") returns ['H','o','o','o','o','t']

11 Write a function noDupeMatch() that take two lists, it returns the number of the elements in the first list that appears in the second list. When the item is a duplicate you do not count it twice. You must design a way to keep track of what you already counted so you do not count the duplicates.

noDupeMatch( [1,2,3] , [1,3,5] ) returns 2

noDupeMatch( [3,3,3] , [3,3,3,3,3] ) returns 1
noDupeMatch( [1,2,3] , [3,3,3,4,5] ) returns 1
noDupeMatch( [5,6,2,8] , [8,6,5,4,2,5,8] ) returns 4