Skip to content

Practise #03

Assignment 11

  1. Create an assert statement that throws an AssertionError if the variable spam is a negative integer.
  2. Write an assert statement that triggers an AssertionError if the variables eggs and bacon contain strings that are the same as each other, even if their cases are different (that is, 'hello' and 'hello' are considered the same, and 'goodbye' and 'GOODbye' are also considered the same).
  3. Create an assert statement that throws an AssertionError every time.
  4. What are the two lines that must be present in your software in order to call logging.debug()?
  5. What are the two lines that your program must have in order to have logging.debug() send a logging message to a file named programLog.txt?
  6. What are the five levels of logging?
  7. What line of code would you add to your software to disable all logging messages?
  8. Why is using logging messages better than using print() to display the same message?
  9. What are the differences between the Step Over, Step In, and Step Out buttons in the debugger?
  10. After you click Continue, when will the debugger stop ?
  11. What is the concept of a breakpoint?

Assignment 12

  1. In what modes should the PdfFileReader() and PdfFileWriter() File objects will be opened?
  2. From a PdfFileReader object, how do you get a Page object for page 5?
  3. What PdfFileReader variable stores the number of pages in the PDF document?
  4. If a PdfFileReader object’s PDF is encrypted with the password swordfish, what must you do before you can obtain Page objects from it?
  5. What methods do you use to rotate a page?
  6. What is the difference between a Run object and a Paragraph object?
  7. How do you obtain a list of Paragraph objects for a Document object that’s stored in a variable named doc?
  8. What type of object has bold, underline, italic, strike, and outline variables?
  9. What is the difference between False, True, and None for the bold variable?
  10. How do you create a Document object for a new Word document?
  11. How do you add a paragraph with the text 'Hello, there!' to a Document object stored in a variable named doc?
  12. What integers represent the levels of headings available in Word documents?

Assignment 13

  1. What advantages do Excel spreadsheets have over CSV spreadsheets?
  2. What do you pass to csv.reader() and csv.writer() to create reader and writer objects?
  3. What modes do File objects for reader and writer objects need to be opened in?
  4. What method takes a list argument and writes it to a CSV file?
  5. What do the keyword arguments delimiter and line terminator do?
  6. What function takes a string of JSON data and returns a Python data structure?
  7. What function takes a Python data structure and returns a string of JSON data?

Assignment 14

  1. What does RGBA stand for?
  2. From the Pillow module, how do you get the RGBA value of any images?
  3. What is a box tuple, and how does it work?
  4. Use your image and load in notebook then, How can you find out the width and height of an Image object?
  5. What method would you call to get Image object for a 100×100 image, excluding the lower-left quarter of it?
  6. After making changes to an Image object, how could you save it as an image file?
  7. What module contains Pillow’s shape-drawing code?
  8. Image objects do not have drawing methods. What kind of object does? How do you get this kind of object?

Assignment 15

  1. How many seconds are in an hour? Use the interactive interpreter as a calculator and multiply the number of seconds in a minute (60) by the number of minutes in an hour.
  2. Assign the result from the previous task (seconds in an hour) to a variable called seconds_per_hour.
  3. How many seconds do you think there are in a day? Make use of the variables seconds per hour and minutes per hour.
  4. Calculate seconds per day again, but this time save the result in a variable called seconds_per_day.
  5. Divide seconds_per_day by seconds_per_hour. Use floating-point (/) division.
  6. Divide seconds_per_day by seconds_per_hour, using integer (//) division. Did this number agree with the floating-point value from the previous question, aside from the final .0?
  7. Write a generator, genPrimes, that returns the sequence of prime numbers on successive calls its next() method: 2, 3, 5, 7, 11, ...

SOLUTIONS

Click Here
  • [Assignment 11 Solution]
  • [Assignment 12 Solution]
  • [Assignment 13 Solution]
  • [Assignment 14 Solution]
  • [Assignment 15 Solution]
Back to top