Embercode
✕
ConditionalsQuick quiz

Guards and De Morgan

8 questions. Covers De Morgan rewrites in Python.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``python def greet(age): if age < 18: print("Too young", end=" ") print("Welcome", end=" ") greet(15) print("|") ``
  2. 2. What does this program print? ``python paid = True in_stock = False print(not (paid and in_stock), not paid and not in_stock) ``
  3. 3. A function should decline a withdrawal of zero or less. Which part is wrong? ``python def withdraw(amount): if amount > 0: return "declined: amount must be positive" return "approved" ``
  4. 4. A reader rewrites not (is_admin and is_owner) as not is_admin and not is_owner. Which statement is correct?
  5. 5. Does a guard clause that ends in return let the code below it skip an else?

5 question(s) left on this page.