Write a class Time
that represents a time of day with 1-second resolution, e.g.
11:32:07.
Include a static method make
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
Vector
that represents a vector in n-dimensional space.
Provide an initializer that takes a list of numbers, yielding a vector with those components.
The '+' operator should add two vectors.
The '*' operator should multiply a scalar times a vector, yielding a new vector.
The '*' operator should compute the dot product of two vectors, yielding a scalar.
Provide a method v.length() that computes the length of a vector.
Provide a method v.angle(w) that computes the angle between two vectors in radians.
A vector should have a string representation such as "[3.25 5.02 -6.12]", with two digits after the decimal point in each component.
You are given a class
LinkedList
with
a single attribute head
that
points to the head of a linked list. Each list node is an instance of
the Node
class:
class Node: def __init__(self, val, next): self.val = val self.next = next class LinkedList: def __init__(self, head): self.head = head
Write a method that
deletes all odd values
from a LinkedList
of integers.