Difference between revisions of "IB Computer Science 1"

From WLCS
Line 3: Line 3:
 
* Benford's Law Assignment
 
* Benford's Law Assignment
 
*# Create a text file that contains a list of 1000 numbers from a naturally occurring data set
 
*# Create a text file that contains a list of 1000 numbers from a naturally occurring data set
 +
*#* If you cannot find one, try to get one from here: [http://testingbenfordslaw.com/ Testing Benford's Law]
 
*# Write a python program that reads the file, extracts the first digit of every number, and determines the frequencies of 0-9
 
*# Write a python program that reads the file, extracts the first digit of every number, and determines the frequencies of 0-9
 
*# Print out the frequencies (percentages) of the numbers 0 through 9
 
*# Print out the frequencies (percentages) of the numbers 0 through 9

Revision as of 15:20, 8 December 2014

Monday - Thursday (12/8/14 - 12/11/14)

Agenda:

  • Benford's Law Assignment
    1. Create a text file that contains a list of 1000 numbers from a naturally occurring data set
    2. Write a python program that reads the file, extracts the first digit of every number, and determines the frequencies of 0-9
    3. Print out the frequencies (percentages) of the numbers 0 through 9

Wednesday - Thursday (12/3/14 - 12/4/14)

Agenda:

  • Complete the rest of the File I/O, List & String Practice
    1. Assume you have a single string containing the entire U.S. Constitution. Calculate and print out the frequency of the word "the"
      • Download the following file: Media:Constitution.txt
      • Hint: There is a useful string function converts a string to a list of words.
    2. Assume you have a single data file with 1000 random numbers from 0 to 100. Print out the frequency of each of the numbers.
      • Example code to help read in a file:
  • Benford's Law
    1. Read and watch Benford's Law and Fraud Detection
    2. Further reading Benford's Law
    3. Research and find a set of naturally occurring numbers. Here are some ideas, but you can come up with your own:
      • U.S. Census Bureau
      • Heights of mountains
      • Atomic weights in the periodic table
      • Baseball statistics
      • etc.
    4. Create a text file that contains a list of your numbers (try to have a list of 1000 numbers if possible)

Monday - Tuesday (12/1/14 - 12/2/14)

Agenda:

  • Demo any missing assignments
  • File Input/Output (reading/writing)
  • List & String Practice
    1. Test out the snippet of code below
    2. Analyze how it each line works and what each line does
    3. Try to complete the following exercises
    4. Assume you have a list of strings of peoples' full names in random order. Print out an alphabetized list of only the last names.
    5. Assume you have a single string containing the entire U.S. Constitution. Calculate and print out the frequency of the word "the"
      • Download the following file: Media:Constitution.txt
      • Hint: There is a useful string function converts a string to a list of words.
    6. Assume you have a single data file with 1000 random numbers from 0 to 100. Print out the frequency of each of the numbers.
      • Example code to help read in a file:
# open a text file
file = open("Constitution.txt", "r")

# read all lines in the file and save in the constitution string variable
constitutionStr = file.read()

# close the file
file.close()

print(constitutionStr)

Archives