Write a function is_palindrome(s, i, j) that is true if the substring s[i:j] is a palindrome. You may not use any loops or slice operations, so you will need to use recursion.
Write a function randomTree(h)
that
builds a complete binary tree of height h. Every value in the tree
should be a random integer in the range 0 .. 999.
Write a
function that takes a dictionary such as { 'green' :
'zelený', 'red' : 'červený' }
and
returns a corresponding dictionary in which the keys and values have
been flipped, e.g. { 'zelený' : 'green', 'červený' :
'red'}
.
Write
a class Time
that represents a time of day with 1-second
resolution, e.g. 11:32:07.
Include an
initializer that takes three integers (hours, minutes,
seconds) and returns a Time
. Seconds should default to
0 if not provided.
The
'+' operator should add a number of seconds to a Time
,
yielding a new Time
object (wrapping past midnight if
necessary).
The '-' opertator should subtract two Time
objects, yielding a (possibly negative) number of seconds.
A
Time
object's
string representation should look like this: "11:32:07".
Write a class Date representing a month and day. The class should support these operations:
Date(m, d) – make a Date representing the given month (1 ≤ m ≤ 12) and day (1 ≤ d ≤ 31)
d.next() - return the Date after d
d.prev() - return the Date before d
d.as_string() - return a string such as "May 15"
d.add(n) – add n days to the given Date, wrapping past Dec 31 to Jan 1 if necessary
Write a class Polynomial representing a polynomial of a single variable. The class should support these operations:
Polynomial(c) – make a Polynomial with the given coefficients. For example, Polynomial(3, 2, 1) represents the polnomial 3x2 + 2x + 1.
p.degree() - return the degree of this Polynomial
The '+' operator should add two Polynomials.
The '*' operator should multiply two Polynomials.
p.eval(x) – return the value of the Polynomial at the given value of x
A Polynomial should have a string representation such as "3x^2 + 2x + 1".