Lecture 22

posted Mar 6, 2013, 6:05 AM by Samuel Konstantinovich   [ updated Mar 6, 2013, 8:30 AM ]
Do now: 
If you need to read the course notes from the past two days to help you answer the questions, that is fine. Also, the ASCII table you printed might help you figure out the patterns. 
1. How do you determine if a character is upper or lower case?
2. What is the ord('a'), what is the ord('n') ? 
3. What do you do to change 'a' to 'n' in rot13? What do you do to change 'n' to 'a' in rot13?
4. Which letters of the alphabet follow the same pattern as 'a' ? Which letters follow the same pattern as 'n' ?

Discussion of resources available to all students.

Pair programming practice, You must work in pairs. You may only log into one machine per two people. 
*You are tasked with solving a variety of problems. There are examples at the end of all of the questions.
*Everyone should solve all problems on their own time as homework if they didn't/couldn't in class. 
*I will assume you completed these when designing my next quiz or test. (There is probably a quiz some time next week)
*Some of these functions have a built in python function that accomplishes the same task. You must write this without using such functions so don't the built in upper function to write toUpper.
*Read the questions AND look at the examples below.

[hint for ABCD: Remember since strings cannot be changed, you have to make a new string to return. ]

A. toUpper(s) will accept a string as a parameter and returns the same string with all lower case letters replaced with upper case. Upper case letters and symbols do not change.

B. stringReverse(s) will accept a string as a parameter, and return a string with the characters in the reverse order.

C. countCharInString(s,c) will accept a string s and a character c, it will then return how many times that character appears in the string.

D. makeBoxOfNumbers(rows,cols) will accept two integers rows and cols, it will then create a string with a box of numbers that is rows digits tall, and cols digits wide. It ends each row with a newline character so it prints nicely. The numbers should be the numbers 0-9 repeated over and over again. (You can easily do this by counting normally and only looking at the ones digits ... 7 8 9 10 11 12 -> 7 8 9 0 1 2)

E. findInString(part,target) accepts two strings and tells you what is the first index of the target string that you can find the part string. If part does not appear in the string the function returns -1. (Hint look at slices!)

F. removeFromString(s,c) accepts a string and a character, and returns the string with all instances of that character removed. (Hint: more slices!)

stringReverse('hello') returns 'olleh'

toUpper('Bing! Wah?') returns 'BING! WAH?'

countCharInString('Bobby Brown','b') returns 2  (capitalization matters)
countCharInString('Too Hot To Hoot','o') returns 6

makeBoxOfNumbers(3,6) returns: '123456\n789012\n345678\n'
that string would print like this:

findInString('bob','Bobby') returns -1
findInString('bob','bobby') returns 0
findInString('by','Abbye by bye') returns 2

removeFromString('Bloop pow woot', 'o')  returns 'Blp pw wt'
removeFromString('ich bin ein holtzfäller', ' ') returns 'ichbineinholtzfäller'