Page 143 -
P. 143

persistence


                          Code Magnets


                          Add the code magnets at the bottom of this page to your existing
                          code to satisfy the following requirements:

                          1. Create an empty list called man.
                          2. Create an empty list called other.
                          3. Add a line of code to remove unwanted whitespace from the
                          line_spoken variable.
                          4. Provide the conditions and code to add line_spoken to the
                          correct list based on the value of role.
                          5. Print each of the lists (man and other) to the screen.






                    try:
                        data = open('sketch.txt')
                        for each_line in data:
                            try:
                                (role, line_spoken) = each_line.split(':', 1)













                            except ValueError:
                                pass
                        data.close()
                    except IOError:                                                         Here are your magnets.
                        print('The datafile is missing!')





                                                              elif role == 'Other Man':
                    if role == 'Man':                      man = []

               line_spoken = line_spoken.strip()         other = []            other.append(line_spoken)

                                                                                print(man)
                    print(other)
                                               man.append(line_spoken)
                                                                                      you are here 4    107
   138   139   140   141   142   143   144   145   146   147   148