Introduction to Programming with Python
Day 3

David Garcia, University of Konstanz

Quiz I

  1. In the following code, what is the output?
dogs = ['willie', 'hootz', 'peso', 'monty', 'doggy']
if len(dogs) >= 5:
  print("Holy mackerel, we might as well start a dog hostel!")
elif len(dogs) >= 3:
  print("Wow, we have a lot of dogs here!")
else:
  print("Okay, this is a reasonable number of dogs.")
  1. In the following code, what is the output?
num = 3
if num >= 3:
    num = 1
    print("one")
elif num == 1:
    num = 3
    print("three")
elif num == 3:
    print("???")
print(num)

Quiz II

  1. In the following code, what is the output?
from datetime import datetime
date = ['Feb 09 2020', 'Feb 09 2020', 'Feb 09 2020', 'Feb 03 2020', 'Feb 03 2020']
formatted_dates = [ \
  datetime.strptime(d, '%b %d %Y').strftime("%Y-%m-%d") \
  for d in date ]
print(formatted_dates)
  1. Using list comprehension, write one line of code that, from a list of dates, creates a list of tuples where each tuple contains a unique date and the count of its occurrences.
#Your code here

Feedback on Day 2