Difference between revisions of "IB Computer Science 1"

From WLCS
Line 1: Line 1:
== Thursday - Friday (2/23/17 - 2/24/17) ==
+
== Monday - Tuesday (2/27/17 - 2/28/17) ==
* Introduction to [https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files File Reading & Writing (Input & Output)]
+
'''Agenda:'''
*# Assume you have a single string containing the entire U.S. Constitution.  Calculate and print out the frequency of the word "the"
+
* File Reading/Writing (Input/Output) Review
*#* Download the following file: [[Media:Constitution.txt]]
+
* Complete the File R/W (I/O) Exercises:
*#* Hint: There is a useful string function that converts a string to a list of words.
 
 
*# Write a program that generates a textfile with 10000 random numbers from 0-100
 
*# Write a program that generates a textfile with 10000 random numbers from 0-100
*# Read a file with 10000 random numbers from 0 to 100.  Print out the frequency of each of the numbers.
+
*# Read a file with 10000 random numbers from 0 to 100.  Print out the frequency of each of the numbers (Hint: Use a list to track the frequencies)
*# Read a file with first and last names of people.  Print out a list of all their initials
+
*# Read a file with first and last names of people.  Print out a list of all their initials.  Output that list of initials to a file
  
 
* Example code to help read in a file:
 
* Example code to help read in a file:
Line 38: Line 37:
 
file.close()
 
file.close()
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== Thursday - Friday (2/23/17 - 2/24/17) ==
 +
* Introduction to [https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files File Reading & Writing (Input & Output)]
 +
*# 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 that converts a string to a list of words.
  
 
== Tuesday - Wednesday (2/21/17 - 2/22/17) ==
 
== Tuesday - Wednesday (2/21/17 - 2/22/17) ==

Revision as of 09:23, 27 February 2017

Monday - Tuesday (2/27/17 - 2/28/17)

Agenda:

  • File Reading/Writing (Input/Output) Review
  • Complete the File R/W (I/O) Exercises:
    1. Write a program that generates a textfile with 10000 random numbers from 0-100
    2. Read a file with 10000 random numbers from 0 to 100. Print out the frequency of each of the numbers (Hint: Use a list to track the frequencies)
    3. Read a file with first and last names of people. Print out a list of all their initials. Output that list of initials to a file
  • 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()

# read all lines from the file and save them to a listlist
constitutionList = file.readlines()

# close the file
file.close()

print(constitutionStr) # What does it print?  Comment this line out and uncomment the next line
#print(constitutionList)
  • Example code to help write to a file:
# open a text file
file = open("output.txt", "w")

# read all lines in the file and save in the constitution string variable
file.write("Hello!\n")
file.write("world!")

# close the file
file.close()

Thursday - Friday (2/23/17 - 2/24/17)

  • Introduction to File Reading & Writing (Input & Output)
    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 that converts a string to a list of words.

Tuesday - Wednesday (2/21/17 - 2/22/17)

Agenda:

Thursday - Friday (2/16/17 - 2/17/17)

Agenda:

Monday - Wednesday (2/13/17 - 2/15/17)

Agenda:

Thursday - Friday (2/9/17 - 2/10/17)

Agenda:

Tuesday - Wednesday (2/7/17 - 2/8/17)

Agenda:

Wednesday - Monday (2/1/17 - 2/6/17)

Archives