Archive for the ‘Computer Science’ Category

Code Wars – Strings


Be sure to read the Code Wars rules here before starting. Then click on the link below to open a PDF with the problem.

Code Wars: Strings

Let us know how Code Wars worked for you by rating this post.

Why Study Square Roots?


(Originally pulished 2/22/2012)
#1 Answer on Yahoo Answers: If you want a square swimming pool (or anything square) a certain area, find the square root of the area and you will know the length of the sides.
•How else can you solve X^2 = 25 (and other fancy mathematical problems)?
•So Pythagoras could create his little theorem: a**2 + b**2 = c**2

Leave a comment

Add your own answer to “Why study square roots?”

Computer Science Week 12/9 – 12/15


Assignment 1: Watch one of the following videos at home (one is YouTube so it will not open at school).

Assignment 2: Leave a comment below this post with a pledge of what you will do to promote Computer Science this week. (40 pts)

Things I’ve done:

  • I’ve added this post
  • I’ve added the Computer Science Teachers Association logo to my signature on email
  • I’ve discussed Computer Science and the nation-wide lack of girls with the counselors and administration
  • I will remind the counselors that CS at Kamiakin is a .5 math credit and it satisfies the Computer Applications graduation requirement.

Things You Can Do:

  • One day this week, bring a friend to lunch in the room and show them the lab, Scratch, and/or Python (40 pts)
  • Talk to two friends about Computer Science and that the current job market is one of the largest and growing for Computer Science and Computer Engineering related careers. (20 pts)
  • Sign up for the LAN Party and bring a friend who has never attended (they are free) (40 pts)
  • Write 2-3 paragraphs describing Computer Science to a student who does not know what it is for me to post on the blog during CS Week. (20 pts)
  • If you have another idea, talk to me about it.

Raspberry Pi


Check this video out. How does it relate? The Raspberry Pi runs on Linux plus you can program to do fun stuff with Python!

http://www.wimp.com/raspberrypi/

If you are interested in persuing this as a 2nd semester project, let me know.

Things I’ve Learned


Things I Have Learned while studying Lists:

  1. What a “set” is
  2. Sets are faster for membership testing than lists (Stackoverflow.com)
  3. Stackoverflow.com is an awesome resource (actually just confirmed it)
  4. The Zen of Python: I have the key.

If you want to attain the Zen of Python, comment regarding something significant that you have learned in this unit. It can be short but must be well written and thoughtful. I will then award you the key. (10 pts)

.join( )


As we were studying lists and the .join( ) method, I thought the syntax was odd. If you remember, we discussed that for a list such as,

>>> s = ['ratta', 'tata', 'tata', 'tat']

we could convert it to a string using .join( ) and a delimiter (in this case a space):

>>> ” “.join(t)

This would produce:

(“ratta tata tata tat”)

” “.join(t) looks odd to me. I thought it would should be t.join(” “). So I did some searching on the intertubes. I found my answer, not too shockingly, at stackoverflow.com.

Click the link, read the questions and responses then comment as to why you think  ” “.join(t) was selected by Python developers to convert a list into a string.

Homework: 10 pts.

List Shortcut


When creating a list, you can skip adding all the quotes around and commas between elements of the list. Let Python do it for you by creating a string then convering it to a list using the .split() method.

>>> cheeses= “cheddar gouda swiss”.split()
>>> cheeses
['cheddar', 'gouda', 'swiss']

Get Adobe Flash player

Jon M. for his contribution

 

 

Think Python, Chapter 10, Lists: 10-1 & 10-2


Read 10-1 thru 10-2 in Think Python.

After reading, add a comment (question or question) on this post regarding a question you have after the reading and doing examples or a comment which summarizes your understanding.  Your comment must

  • Show depth of understanding
  • Can be an extension of the reading as in something you know about the subject but was not covered
  • Will be proof you have read the two sections
  • Merely quoting the text is not acceptable

Comments will account for 10% of your grade for this part of the unit.

We will do the examples in class tomorrow.

Top 10 Programming Languages to Keep You Employed


Check out this article at eWeek.com

Code War Results


1st:  Jon A. and Jon M. (19/20 pts)

2nd: Spencer B. and David M (19/20 pts: 2nd due to file saving technicality)

3rd: Devin S. and Kendall T. (16/20 pts)

4th: Hannah N. and Nicole J. (15/20 pts)

Solutions

 Problem 1: “Fill in the Blanks” (4 pts)

Write a program which:

  • Takes a parameter  for secretString (string)
  • Counts the number of letters in secretString
  • Creates a new variable containing a string of the same number of underscores as there are characters in the first variable
  • Prints the new variable

Example 1:
secretString = “kingarthur”
variable2 = “_ _ _ _ _ _ _ _ _ _” (spaces added for visibility but not required for the problem)

Example 2:
secretString = “12345”
variable2 = “_ _ _ _ _” (spaces added for visibility but not required for the problem)

def cw02(secretString):

    secretString = len(secretString) * “_”

    print (secretString)

cw02(“foo”)

 >>>cw02(foo)

_ _ _

(spaces added as visual separator only)

Problem 2: “String it Along” (3 pts)

Write a program which:

  • Takes a parameter  for secretString (string)
  • Iterates through the length of secretString
  • Prints secretString one letter at a time horizontally
  • The function may not use the print() function alone, it must use a loop

Example 1:
secretString = “spam”
Results:
spam

Example 2:
secretString = “foo”
Results:
foo

def cw01(secretNumber):

    for i in secretNumber:

                   print (i)

 >>> cw01(“123”)

1

2

3 

Problem 3: “Number, Please” (5 pts)

Write a program which:

  • Takes two parameters
  •  Using these variables, a for loop, and if statement, compares characters in secretString and correctCharacters
  • Returns only characters that are in both
    • For secretString (string) and correctCharacters (string)

Example 1:
secretString = “foo”, correctCharacters= “o”
Results:
o
o
Example 2:
secretString = “56789″, correctCharacters = “57″
Results:
5
7

def cw03(secretString, correctCharacters):

    for i in range(len(secretString)):

        if secretString[i] in correctCharacters:

            print (secretString[i])

>>>cw03(“foo”, “o”)

o

o

Problem 4: “Spacing Out” (8 pts)

Create a program which:

  • Takes two parameters
  • Creates a variable named “blanks” which creates a string containing underscores equal to the length of  secretString
  • Use if statement and for loop to  replace underscores in “blanks”  with correct characters of secretString
  • Prints the final result with a space between all underscores and letters
    • secretString; a string
    • correctCharacters; a string which contains all or some of the characters  in secretString

Example 1:
secretStirng = “01234″, correctCharacters = “24″
Results:
_ _ 2 _ 4

Example 2:
secretString = (knightswhosayni                ), correctCharacters=”nis”
Results:
_ n i _ _ _ s _ _ _ s _ _ n i

 def cw04(secretString, correctCharacters):

    blanks=len(secretString) * “_”

    for i in range(len(secretString)):

        if secretString[i] in correctCharacters:

            blanks=blanks[:i] + secretString[i] + blanks[i+1:]

    for letter in blanks:

        print (letter, end=” “)

 

cw04(“scope”, “op”)

Return top