Lecture 12 – Quiz 1 Review

Data 6, Summer 2021

Hours, minutes, and seconds

Temperature conversion

Suppose we have a list of temperatures of cities around the world.

Remember, we already defined c_to_f, which takes a temperature in Celsius to a temperature in Fahrenheit.

How do we convert the 3rd temperature to Fahrenheit? The 9th temperature? The very last temperature in the list?

Quick Check 1

Quick recap: while loops allow us to repeat a code block as long as some boolean expression is true.

Back to the question at hand: how do we make a new list with all temperatures converted to Fahrenheit?

Stock prices

Part 1

Task: Given a list of prices of a stock on a single day, return a string describing whether the stock increased, stayed the same, or decreased from its starting price.

Part 2, Quick Check 2

Task: Given a list of prices of a stock on a single day, return True if the stock was strictly increasing, and False otherwise. A list of numbers is strictly increasing if each one is larger than the previous.

Next day of the week

More Practice

Given the side lengths of a triangle as a list (sides), return:

If any of the side lengths are less than or equal to 0, return 'invalid'.

Answer def triangle_type(sides): if sides[0] <= 0 or sides[1] <= 0 or sides[2] <= 0: return 'invalid' if sides[0] == sides[1] == sides[2]: return 'equilateral' elif (sides[0] == sides[1]) or (sides[1] == sides[2]) or (sides[0] == sides[2]): return 'isoceles' else: return 'scalene'

Prefixes, Quick Check 2

Kaprekar's constant