Options with circles are single-select (exactly one), while options with squares are multi-select (zero or more).
RecursionErrordef halfsies(n):
return if n <= 1 then 0 else halfsies(n / 2)+1def halfsies(n):
if n < 1:
return 0
else:
return halfsies(n / 2)+1def halfsies(n):
if n <= 1:
return 0
return halfsies(n / 2)+1
def halfsies(n):
return halfsies(n / 2)+1 if n > 1 else 0def halfsies(n):
if n <= 1:
return 0
else:
return halfsies(n / 2)+1
def mystery(a):
return a if len(a) <= 1 else mystery(a[len(a)//2:]) + mystery(a[:len(a)//2])
count(4) return?
def count(depth):
if depth == 0:
return 1
return 1 + count(depth - 1) + count(depth - 1)
for, no while, no comprehensions), write a recursive function called count_vowels that returns the number of vowels (a, e, i, o, u, lowercase only) in a string. For example, count_vowels("banana") is 3 and count_vowels("") is 0.
Person class did not define a __str__ method, what would print(Person("Alice")) show?
AlicePerson("Alice")<__main__.Person object at 0x104f2ad50>TypeErrorPerson class has the method
def is_sibling_of(self, other):
return self.mom is other.mom or self.dad is other.dad
and we write:
adele = Person("Adele", mom=Person("Marie"), dad=Person("Pierre"))
joseph = Person("Joseph", mom=Person("Marie"), dad=Person("Pierre"))
What is the value of adele.is_sibling_of(joseph), and why?
True, because both people have a mom named Marie and a dad named PierreFalse, because four different Person objects were created for the parents, so Adele's mom is not the same object as Joseph's momFalse, because is only works on numbers and stringsself was never passed inadele.is_sibling_of(joseph) is a shortcut for which of the following?
is_sibling_of(joseph, adele)Person.is_sibling_of(adele, joseph)Person.is_sibling_of(self, adele, joseph)joseph.is_sibling_of(adele)Card class from The Real Deal lab?
from dataclasses import dataclass@dataclass decorator just above the classrank: int__init__ method that assigns self.suit and self.rank__post_init__ method__post_init__ method called?
card.__post_init__()__init__ assigns the attributes
from dataclasses import dataclass
@dataclass(frozen=True)
class Card:
suit: str
rank: int
a = Card("S", 12)
b = Card("S", 12)
which of the following are true?
a == b is Truea is b is Truea.rank = 13 raises an errorCard("S") raises an errorCard(rank=12, suit="S") makes a card equal to aColor with fields red, green, and blue. Every color created must be a legal RGB color: if any field is not an int, raise a TypeError, and if any field is outside the range 0 to 255, raise a ValueError. Include the import.
K for black, W for white, R for red, G for green, B for blue, Y for yellow, A for gray
(0, 0, 255)(255, 255, 0)(0, 0, 0)(128, 128, 128)(0, 255, 0)(255, 255, 255)(12, 200, 255)(256, 0, 0)(0, 0)(0, 0, 0)(100, -5, 100)
def f(s):
try:
n = int(s)
print("A")
print(100 // n)
except ValueError:
print("B")
except ZeroDivisionError:
print("C")
what is printed by each of the following calls?
f("5") _____________________________
f("0") _____________________________
f("dog") _____________________________
TypeError for the wrong type, ValueError for the right type but a bad value," write T or V in each blank for the error that a well-written Card class (suits "S", "H", "D", "C", ranks 1 through 13) should raise:
Card("X", 5)Card("S", "5")Card("H", 14)Card(7, 7)Card("D", 0)python hanoi.py 4, which expression gives the number of disks as an integer?
sys.argv[0]sys.argv[1]int(sys.argv[0])int(sys.argv[1])int(sys.argv)python total.py 3 10 -2 prints 11, and python total.py prints 0. If any argument is not an integer, print All arguments must be integers instead of a sum.