Difference between revisions of "IB Computer Science 1"
From WLCS
Line 1: | Line 1: | ||
+ | == Thursday - Friday (12/5/13 - 12/6/13) == | ||
+ | '''Agenda:''' | ||
+ | * Text-based card game introduction exercises | ||
+ | *# Create a text file that has all the names for a deck of cards (Examples: 5 of Diamonds, Jack of Clubs) | ||
+ | *# Write a program that loads the text file's data into a list of strings | ||
+ | *#* Look through [http://docs.python.org/3.3/tutorial/inputoutput.html#reading-and-writing-files Python-reading and writing files] and find the the '''f.readlines()''' function | ||
+ | *# Store all the strings loaded into a list of strings named deck | ||
+ | *# Create 2 empty lists named p1Hand and p2Hand | ||
+ | *# Deal 5 cards from the deck to p1Hand | ||
+ | *#* Look through [http://docs.python.org/3.3/tutorial/datastructures.html#more-on-lists Python-Lists] and find the '''list.pop()''' function. Read how the functions works to remove elements from a list. You can then use the '''list.append()''' function to add those elements to another list | ||
+ | *# Deal 5 cards from the deck to p2Hand | ||
+ | *# Print out both hands | ||
+ | |||
== Monday - Wednesday (12/2/13 - 12/4/13) == | == Monday - Wednesday (12/2/13 - 12/4/13) == | ||
'''Agenda:''' | '''Agenda:''' | ||
Line 21: | Line 34: | ||
print(constitutionStr) | print(constitutionStr) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Archives == | == Archives == | ||
* [[IBCS1 - 1314 - November]] | * [[IBCS1 - 1314 - November]] | ||
* [[IBCS1 - 1314 - October]] | * [[IBCS1 - 1314 - October]] | ||
* [[IBCS1 - 1314 - September]] | * [[IBCS1 - 1314 - September]] |
Revision as of 11:03, 5 December 2013
Thursday - Friday (12/5/13 - 12/6/13)
Agenda:
- Text-based card game introduction exercises
- Create a text file that has all the names for a deck of cards (Examples: 5 of Diamonds, Jack of Clubs)
- Write a program that loads the text file's data into a list of strings
- Look through Python-reading and writing files and find the the f.readlines() function
- Store all the strings loaded into a list of strings named deck
- Create 2 empty lists named p1Hand and p2Hand
- Deal 5 cards from the deck to p1Hand
- Look through Python-Lists and find the list.pop() function. Read how the functions works to remove elements from a list. You can then use the list.append() function to add those elements to another list
- Deal 5 cards from the deck to p2Hand
- Print out both hands
Monday - Wednesday (12/2/13 - 12/4/13)
Agenda:
- Demo Advanced Python List Exercises
- List & String Practice
- Assume you have a list of strings of peoples' full names in random order. Print out an alphabetized list of only the last names.
- 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.
- 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)