To Lecture Notes

IT 211 -- Mar 4, 2019

Review Exercises

  1. Explain what this statement means from Project 6:
    new_photo_name = "{:s}/{:03d}-{:%s}". /
        format(folder_name, counter, original_photo_name)
    
    Ans: "{:s}/{:03d}-{:%s}" is a format string and {:s}, {:03d}, {:%s} are format specifiers. Each time that a format specifier occurs in the format string, the corresponsing argument of the format method is entered in the output string. {:s} means that a str object will be included; {:03d} means that a decimal number with field width 3 with leading zeros will be included. The resulting string for the eiffel tower in paris is "paris/001-eiffel-tower.jpg"
  2. Write python statements to do the following:
    1. Create an empty dictionary. Ans:
      d = { }
      
    2. Add the new key-value pairs age: 35, id: 1234 Ans:
      d["age"] = 35
      d["id"] = 1234
      
    3. Print the number of key-value pairs in the dictionary. Ans:
      print(len(d))
      
    4. Print all the key-value pairs in the dictionary. Ans:
      for key in d:
          print(key, ":", d[key])
      
  3. Suppose you have three persons, whose information you want to represent:

    Variable name name gender age
    child_alice "Ally"  "F"  11
    child_robert "Bob"  "M"   9
    child_susan "Sue"  "F"  10

    Represent this information as (a) three lists, (b) three tuples, (c) three dictionaries.
    Ans: Here is the solution with the output.

Classes and Objects

Reference: docs.oracle.com/javase/tutorial/java/concepts/object.html

Project 7