Homework

38, Due Fri., 5/25
     1. See post 37 listed below.
     2. In order to transfer files from home to school, I'd suggest  downloading and installing 
         Filezilla.
                      https://filezilla-project.org/

         host: homer.stuy.edu
         port : 22
         

37, Due Fri. 5/25
     (Weighted as a 1/4 of an exam)
      For each group, staple together and hand in:
        1. Signed Task Completion Sheet.
        2. Robot code printed out.
        3. A one page, single space, document describing what you learned from the robot lab experience.
            Include which tasks you enjoyed and any suggestions for an improved experience.

36. Due Mon. 5/14 
      Complete parts (c) and (d) in the DictLab.
   

35. Due Thurs., 5/10
     Complete the following function:

     def reveseDict(d):
         '''Assumes d is  dictionary with unique values.
           Returns None.
           Side effect: interchanges the key-value pairs of d.'''


      Test Run:
       d1 = {'a': 0, 'b': 1 , 'c': 2, 'd' : 3 , 'e' : 4}
       print d1             # prints the initial state
       reverseDict(d1)
       print d1             # prints a dict equivalent to : {0: 'a', 1: 'b', 2 : 'c', 3:  'd' , 4 : 'e'}


34. Due Wed., 5/09

    Write the function reverseDict(d) that takes a dictionary,
    (assume it's values are unique,)and returns a new dictionary
    such that each key-value pair of d is interchanged. The function
    must not produce a side effect.

    phonebook = {'jane': '793-2341' ,'joe':  '321-3523'}
    print phonebook
    reversePhonebook = reverseDict(phonebook)

    print phonebook # {'jane': '793-2341','joe':' 321-3523'}
    print reversePhoneBook # {'793-2341' : 'jane','321-3523' : 'joe'}


    def reverseDict(d):
    '''Assumes d is a dictionary and the values are unique.
   Returns a reverse dicitonary of d, without a side effect.'''
        ans = {}
        for key in d:
            ans[d[key]] = key
        return ans

  
    What would happen if the values of d are not unique?


33. Due Tues, 5/08
    1. Review Cousrework/monthToInts.py
    2. Add code to monthToints.py to
          i. Print each month (in alphabetical order) with it's corresponding int:
                  First 2 lines
                  Apr : 4
                  Aug: 8
         ii, Print only the odd months: 
                   Jan, Mar, May ,...
       **** Put your solution on paper ****


32. Due Thurs., 5/03
     1. Exam # 4 : 5/4
     2. Review practice exam #r posted in the Exams Folder.
         - you'll be given time in class tomorrow to work on it.

31. Due Wed., 5/02
     1. Exam #4 : 5/4
           - FileObject : open(), read(), readline(), readlines(), write(), close()
           - The set data type: set() , set(sequence)
           - The string format method.
     2. Review Coursework/Files/grader.py

30. Due Tues., 5/01
     1. Exam #4: 5/4
     2. Complete Coursework/Files/fileLab3: #2
             - Use roster.csv 
             - Output should be: 
                Joy,Bill avg:  3.66666666667 
                Lovelace,ADA avg:  3.5 
                Gates,Bill avg:  2.5 
                Dijkstra,Edgar avg:  2.4 
                Hamming,Richard avg:  4.0 *

     3. Review the following code:
            # Version without a loop
def process_v2(filename):
    '''Assumes filename exits with one number per line in ascending order.
       Prints unique values in ascending order.'''
    fileIn = open(filename,'r')
    data = fileIn.readlines()  
    data = reduce(lambda a,b: a if b in a else a + b, data)
    print data
    fileIn.close()

# Version with a loop
def process_v3(filename):
    '''Assumes filename exits with one number per line in ascending order.
       Prints unique values in ascending order.'''
    fileIn = open(filename,'r')
    data = fileIn.readlines()
    data = map(int,data)
    temp = []
    for number in data:
        if number not in temp:
            temp.append(number)
            print number
    fileIn.close()
    
# Version with a set
def process(filename):
    '''Assumes filename exits with one number per line in ascending order.
       Prints unique values in ascending order.'''
    fileIn = open(filename,'r')
    data = fileIn.readlines()  
    data = map(int,data)  
    data = list(set(data))
    data.sort()
    data = map(str,data)
    print '\n'.join(data)
    fileIn.close()


29. Due Fri. 4/27
     1. Exam #4: 5/4
      2. Review a scramble.py from Coursework/Files.
                - Note: 'AUTHOR' scrambled should be 'UATHOR' - versions 2 and 3 interchange correctly.
      3. Complete question 1 from Coursework/Files/fileLab03.txt

28. Due Thurs. 4/26
     1. Exam #4 : **** Rescheduled for 5/4 ****
     2. Review Cousework/Files/removeBlanks.py and occurrences.py
     3. Complete question 5 from Coursework/Files/fileLab02.txt

27. Due Wed. 4/25
     1. Exam#4: 4/27
     2. Review Coursework/Files/avgLen.py
     3. Complete question 3 from Coursework/Files/fileLab02.txt

26. Due Tues., 4/24
     1. Complete question 1 from Coursework/Files/fileLab02.txt.

25. Due Mon. 4/23
      1. Review Coursework/Files : oldestperson.py
       2. Complete question 5 in fileLab01.txt

24. Due Fri.  4/20
      1. Review Coursework/Files : wc.py, data.csv, addRecord.py
      2 Complete questions 3 and 4 in fileLab01.txt

23. Due Wed. 4/18
      Review Coursework/Files/copyupper.py
22. Due Thurs. 4/11
     1. Exam #3 : Fri., 4/13
     2. Review Labs/PigLatin/pigLatin.py
     3. Review Coursework/fib_dynamic_programming.py
     4. Finish Labs/Dynamic_Programming/Lab.txt
21, Due Tues. 4/10
    1. Exam #3: Fri., 4/13
    2. Finish Pig Latin Lab.
    3. Review Coursework/fib_dynamic_programming.py

20. Due Wed. 3/28
     1. From the Coursework directory, review encryptSentence_v3.py.
     2. Write your own version of the function map. Assume the 2nd argument is a list.
          def mymap(f, L):
               '''Assume f is a function and L is a list.
                 Returns a list.'''
           Test cases:
                  mymap(lambda x: x**2, [1,2,3]) -> [1,4,9]
                  mymap(lambda s: len(s) , ['cat' , 'frog']) -> [3,4] 
            Recall, [1,2] + [3] -> [1,2,3]



19. Due Tues., 3/27

      From the Coursework directory, review:
            1. Caesar.py 
             2. encryptSentence.py


18. Due Wed. 3/21
     - In the Coursework Folder review :
         - collatz.py
         - fib.py
17. Due Tues, 3/20
     - See hw_17.txt posted below.

16. Due Mon., 3/19 
      - Review Cousework/default_args.py
      - Complete questions 2 and 3 from  Labs/Lab_Default_Arg.txt


15. Due Thurs., 3/15
      Complete hw15.txt posted below.

14. Due Wed. , 3/14
      A. Review the different versions of upTo(target,L).

  def upTo_V1(target, L):
    ''' Asssume target is an object and L is a list.
        Returns either an empty list or a list containing all the
        items that precede target in L'''
    if target in L:
        x = 0
        while x < len(L):
            if target != L[x]:
                x += 1
            else:
                return L[:x]
    return []

 def upTo_v2(target, L):
    ''' Asssume target is an object and L is a list.
        Returns either an empty list or a list containing all the
        items that precede target in L'''
    ans = []    # accumulator
    if target in L:
        for x in L:
            if x == target:
                break
            else:
                ans += [x]
    return ans

def upTo_v3(target, L):
    ''' Asssume target is an object and L is a list.
        Returns either an empty list or a list containing all the
        items that precede target in L'''
    if target not in L:
        return []
    while target in L:
        L = L[:-1]
    return L

def upTo_v4(target, L):
    ''' Asssume target is an object and L is a list.
        Returns either an empty list or a list containing all the
        items that precede target in L'''
    if target not in L or L[0] == target:
        return []
    for i in range(len(L)):
        if L[i] == target:
            return L[:i]

def upTo(target, L):
    ''' Asssume target is an object and L is a list.
        Returns either an empty list or a list containing all the
        items that precede target in L'''
    if target not in L or L[0] == target:
        return []
    return [L[0]] + upTo(target, L[1:])


      B.Write the function findR(ch, word) that takes a string of length 1,ch, 
         and a string, word. findR(ch,word) returns a nonnegative index position
         of the last occurrence of ch in word. 

         Decide what to do if ch is not in the word.

         Make 2 versions of this function.



13. Due Tues., 3/13
     Write the function upTo(target, L) that takes an object named target and list L 
     and returns a list. The returned list is empty when target is not an item in the list
     or when the target is the first item, otherwise the returned list contains all the
     items of L that precede target in the list.



   Test Cases:
     upTo(3, [1,2,3,4,5]) -> [1,2]
     upTo(5, range(1,100, 4)) -> [1]
     upTo('cat',['dog','cow','chicken']) -> []
     upTo('dog', ['dog','cow','chicken']) -> []
     upTo('chicken', ['dog','cow','chicken']) -> ['dog','cow']   

12. Due Wed., 3/07
      - Exam #2 : 3/09
      - Review hw11_Ans.py posted below.
      - Complete Coursework/forRangeExercises.txt
11. Due Tues. 3/06
      - Exam #2: 3/09
      - Review hw11.txt posted below.
10. Due Mon. 3/05
      - Exam #2 : 3/09
      - Complete questions 1 - 3 from Coursework/whileLoopExercises_II.txt
9, Due Thurs. 3/1
      a. Exam #2 - 3/9
      b. Complete Labs/Strings_ASCII_ART.
8. Due Tues. 2/27
      a. Complete and submit  RPSLab.
      b. Build strDemo.py  that does the following:
            Reads in a string then prints the following:        
                
- the length
                - the first character
                - the last character
                - the middle character
                - the first half of the string
                - the last half of the string
                - repeat the string twice (double it).
                - add 'zzz' to the end of the string

7. Due Thurs. 2/15
     Complete hw_07.txt listed below.

6. Due Wed. 2/14
     * 1. Write the script largest_odd.py that reads in 3 integers and
            prints the largest odd number among them. If none of them
            are odd, it should print a message to that effect.
     * 2. Write the script sort3.py that reads in 3 numbers and prints
            the numbers in increasing order. Create 2 versions, one that
            uses a conditional, the second does not.
 

5. Due Tues. 2/13
            - Write two version of the script, leastOfthree.py, that reads in 3 numbers
               and identifies the least.
               - Version 1: must use a conditional statment.
               - Version 2:  Do not use a conditional. 

4. Due Thurs. 2/8 - Exam #1 - 2/09
                             - Review the scripts located in the Classwork Directory
                                  - even.py, evenorodd.py, initials.py, intOps.py, RGBtoCMYK_v1.py
                             - Modify RGBtoCMYK_v1.py so that when the user inputs all zeros 
                               then the output will be:
                                      cyan    = 0
                                      magenta = 0
                                      yellow  = 0
                                       black   = 1
3. Due Tues. 2/6 - Exam #1 - 2/09
                           - Complete hw_03.txt
                  
2. Due Mon. 2/05 : Exam #1 - 2/09
                               Complete hw_02.txt
1. Due Thurs 2/01: Complete hw_01.txt

ċ
hw11.txt
(1k)
Rick Platek,
Mar 5, 2018, 10:39 AM
ċ
hw11_Ans.py
(2k)
Rick Platek,
Mar 6, 2018, 11:13 AM
ċ
hw_01.txt
(1k)
Rick Platek,
Jan 31, 2018, 4:54 AM
ċ
hw_02.txt
(0k)
Rick Platek,
Feb 2, 2018, 7:10 AM
ċ
hw_03.txt
(1k)
Rick Platek,
Feb 5, 2018, 10:42 AM
ċ
hw_07.txt
(3k)
Rick Platek,
Feb 14, 2018, 10:40 AM
ċ
hw_15.txt
(2k)
Rick Platek,
Mar 14, 2018, 10:56 AM
ċ
hw_17.txt
(1k)
Rick Platek,
Mar 19, 2018, 7:16 AM
Comments