Each of the following questions are worth 3 points.
constructor
pickling
__str__
os.listdir('.')
yes
direct recursion
no. you can only use values that are immutable, that cannot be changed
an instance
False
in an if
statement?
the empty string
ordinary characters, meta-characters, character classes
a match with the greatest number of characters
magic methods
__init__
key - value pairs
a class
5 in s1
a condition under which the recursion will stop
os
rb
indirect recursion
F(1) = 1 F(2) = 1 F(n) = F(n - 1) + F(n - 2)
def fibonacci(number):
if number == 1 or number == 2:
return 1
else:
return fibonacci(number - 1) + fibonacci(number - 2)
title author publisherThese attributes must be HIDDEN and have accessors.
class Book:
def __init__(self, title, author, publisher):
self.__title = title
self.__author = author
self.__publisher = publisher
def get_title(self):
return self.__title
def get_author(self):
return self.__author
def get_publisher(self):
return self.__publisher
def __str__(self):
return self.get_title() + ' by ' + self.get_author() + ', ' + self.get_publisher()
def file_count():
count = 0
entries = os.listdir()
for entry in entries:
if os.path.isfile(entry):
count += 1
return count
Joe 86 Sally 100 Ben 78I am looking for a SINGLE regular expression that matches all lines
(\w+)\s+(\d+)