crash course on python week 2 quiz answers: Shuffle Q/A 1

28. Fill in the blanks to complete the function. The “identify_IP” function receives an “IP_address” as a string through the function’s parameters, then it should print a description of the IP address. Currently, the function should only support three IP addresses and return "unknown" for all other IPs.

29. Can you calculate the output of this code?

def sum(x, y):
return(x+y)
print(sum(sum(1,2), sum(3,4)))

  • 10

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

((24 == 5*2) and (24 > 3*5) and (2*6 == 12))

  • True
  • False
  • 10
  • 15

31. Which of the following are good coding-style habits? Select all that apply.

  • Writing code using the least amount of characters as possible
  • Cleaning up duplicate code by creating a function that can be reused
  • Adding comments
  • Refactoring the code

32. Complete the code to output the statement, “Marjery lives at her home address of 1234 Mockingbird Lane”. Remember that precise syntax must be used to receive credit.

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

Students in a class receive their grades as Pass/Fail. Scores of 60 or more (out of 100) mean that the grade is "Pass". For lower scores, the grade is "Fail". In addition, scores above 95 (not included) are graded as "Top Score".

Fill in the blanks in this function so that it returns the appropriate "Pass", "Fail", or "Top Score" grade.

34. Fill in the blanks to complete the function. The “complementary_color” function receives a primary color name in all lower case, then prints its complementary color. Currently, the function only supports the primary colors of red, yellow, and blue. It returns "unknown" for all other colors or if the word has any uppercase characters.

35. Complete the code to output the statement, “192.168.1.10 is the IP address of Printer Server 1”. Remember that precise syntax must be used to receive credit.

36. What is the value of this Python expression: "blue" == "Blue"?

  • True
  • False
  • orange
  • blue

37. In the following code, what would be the output?

number = 4
if number * 4 < 15:
print(number / 4)
elif number < 5:
print(number + 3)
else:
print(number * 2 % 5)

  • 3
  • 4
  • 7
  • 1

Shuffle Q/A 2

38. Fill in the blanks to complete the function. The fractional_part function divides the numerator by the denominator, and returns just the fractional part (a number between 0 and 1). Complete the body of the function so that it returns the right number. Note: Since division by 0 produces an error, if the denominator is 0, the function should return 0 instead of attempting the division.

39. What are some of the benefits of good code style? Select all that apply.

  • Makes the intent of the code obvious
  • Makes sure the author will refactor it later
  • Allows it to never have to be touched again
  • Easier to maintain

Devendra Kumar

Project Management Apprentice at Google

Leave a Reply