crash course on python week 2 quiz answers

crash course on python week 2 quiz answers

Week 2 Graded Assessment

16. Complete the code to output the statement, “Diego’s favorite food is lasagna”. Remember that precise syntax must be used to receive credit.

name = ___
fav_food = ___
print(name + "’s favorite food is " + fav_food)

  • name = “Diego”
    fav_food = “lasagna”
    print(name + “‘s favorite food is ” + fav_food)

17. What’s the value of this Python expression: 7 < "number"?

  • True
  • False
  • TypeError
  • 0

18. What directly follows the elif keyword in an elif statement?

  • A logical operator
  • A colon
  • A function definition
  • A comparison

19. Consider the following scenario about using if-elif-else statements:

Police patrol a specific stretch of dangerous highway and are very particular about speed limits. The speed limit is 65 miles per hour. Cars going 80 miles per hour or more are given a “Reckless Driving” ticket. Cars going more than 65 miles per hour are given a “Speeding” ticket. Any cars going less than that are labeled “Safe” in the system.

Fill in the blanks in this function so it returns the proper ticket type or label.

20. In the following code, what would be the output?
test_num = 12
if test_num > 15:
print(test_num / 4)
else:
print(test_num + 3)

  • 15
  • 3
  • 12
  • 4

21. Fill in the blanks to complete the function. The character translator function receives a single lowercase letter, then prints the numeric location of the letter in the English alphabet. For example, “a” would return 1 and “b” would return 2. Currently, this function only supports the letters “a”, “b”, “c”, and “d” It returns "unknown" for all other letters or if the letter is uppercase.

22. Can you calculate the output of this code?

def difference(x, y):
z = x - y
return z


print(difference(5, 3))

23. What's the value of this Python expression?

x = 5*2 ((10 != x) or (10 > x))

  • True
  • False
  • 15
  • 10

24. Fill in the blanks to complete the “safe_division” function. The function accepts two numeric variables through the function parameters and divides the “numerator” by the “denominator”. The function’s main purpose is to prevent a ZeroDivisionError by checking if the “denominator” is 0. If it is 0, the function should return 0 instead of attempting the division. Otherwise all other numbers will be part of the division equation. Complete the body of the function so that the function completes its purpose.

25. Code that is written so that it is readable and doesn’t conceal its intent is called what?

  • Maintainable code
  • Self-documenting code
  • Obvious code
  • Intentional code

Shuffle Q/A 1

26. Consider the following scenario about using if-elif-else statements:

The fall weather is unpredictable. If the temperature is below 32 degrees Fahrenheit, a heavy coat should be worn. If it is above 32 degrees but not above 50 degrees, then a jacket should be sufficient. If it is above 50 but not above 65 degrees, a sweatshirt is appropriate, and above 65 degrees a t-shirt can be worn.

Fill in the blanks in the function below so it returns the proper clothing type for the temperature.

27. What's the value of the comparison in this if statement? Hint: The answer is not what the code will print.

n = 4
if n*6 > n**2 or n%2 == 0:
print("Check")

  • Check
  • False
  • 24 > 16 or 0
  • True

Devendra Kumar

Project Management Apprentice at Google

Leave a Reply