2018-02-26 HW

posted Feb 26, 2018, 6:18 AM by Konstantinovich Samuel   [ updated Feb 26, 2018, 9:16 AM ]
Homework complete the codingbat section for Character Manipulation

You should have completed up to "isConsonant" on CodingBat. That is 33 Total problems. The median for the class is completing 32.

You should:
Go to coding bat, and count how many you completed/missed (whichever is smaller)

New Python Idioms:

1a.    in
word = "fish"
print "a" in word
word = "fish"
print "s" in word

This use of in is common in if statements or while loops:
if "s" in word:
    print "contains an s!"

while 's' in word:
    s = s[1:]
print s

1b. The keyword in can be used in a loop too, but this changes what it does, and we will discuss that in much greater detail when we get to lists.

#we will look at this later
for x in "hello":
  print x

2. ASCII table:
Note you care about the Dec column (decimal value ) and the Char column (character value)
We don't care about the first 31

3. chr(i)  vs ord(c)

chr(i) takes a single INTEGER i and converts it to the letter that corresponds to the number on the  ASCII table.

ord(c) takes a single CHARACTER (size 1 string) and converts it to the ASCII value.

CLASSWORK: Use IDLE, remember that these functions should return a result, and that you need to print the function call to see what the results are. 

Note that c and n are parameters, not letters.

In the following problems, assume the parameter c is a string of length 1. 

3a. shiftLetterBy1(c) -> take a string c, and return the next character in the ASCII table.

3b. shiftLetterByN(c,n) -> take a string c, and return the character n letters after it in the ascii table.

3c. uppercaseLetter(c) -> take a string c, and when it is 
  a lower case letter:  return the upper case version of the letter
  any other character: return the original character. DO NOT use str.upper() !