Write a function same_values(l, m) that returns True if the lists l and m contain the same values, i.e. every element of l is in m and every element of m is in l. You may assume that all list elements are immutable.
Write a program that reads text until the end of input is reached, and prints out the most common word in the input text, along with its number of occurrences.
Write a program that reads a string and print out the five most common characters in the string along with their occurrence counts, e.g.
e 23 t 20 o 18 n 15 i 14
Write the characters in decreasing order of frequency. The string may contain any Unicode characters.
Write a class Point representing a point in 2 dimensions. The class should support these operations:
Point(x, y) – make a new point
Write a class Line representing a line segment in 2 dimensions. The class should support these operations:
Line(p, q) – make a line between Points p and q
l.midpoint() - return the midpoint of a line
l.length() - return the length of a line
Write a class Rectangle representing a rectangle in 2 dimensions. The class should support these operations:
Rectangle(p, q) – make a rectangle with corners at Points p and q
r.area() - return the area of a rectangle
r.perimeter() - return the perimeter of a rectangle
r.contains(p) – return true if point p is inside the rectangle r
r.intersects(s) – return true if rectangle r intersects rectangle s
Write a class Circle representing a circle in 2 dimensions. The class should support these operations:
Circle(p, r) – make a circle whose center is at p, with radius r
c.area() - return the area of a circle
c.circumference() – return the circumference of a circle
c.contains(p) – return true if point p is inside the circle c
Write a recursive function
orange(n)
that prints the word 'orange' n times.
Write a function no_zeroes(n) that takes an integer n and returns an integer formed by removing all zeroes from the end of n's decimal representation. For example:
no_zeroes(54000) = 54
no_zeroes(2256) = 2256
As a special case, no_zeroes(0) = 0.
You may not use any loops in your solution, so you will need to write the function recursively.
Write a recursive function isPowOfTwo(n)
that returns True if
n is a power of 2.
Write a function sum(a, i, j) that computes the sum of the values in the range a[i:j]. You may not use any loops or call the built-in sum() function, so you will need to use recursion.
Write a function max(a, i, j) that computes the maximum value in the range a[i:j]. You may not use any loops or call the built-in max() function, so you will need to use recursion.
The Tower of Hanoi is a well-known puzzle that looks like this:
The puzzle has 3 pegs and a number of disks of various sizes. The player may move disks from peg to peg, but a larger disk may never rest atop a smaller one. Traditionally all disks begin on the leftmost peg, and the goal is to move them to the rightmost.
Write a program that reads an integer N and prints a solution to the Tower of Hanoi with N disks. Assume that pegs are numbered from 1 to 3, and all disks begin on peg 1 and must move to disk 3. For example:
How many disks? 2 move disk 1 from peg 1 to peg 2 move disk 2 from peg 1 to peg 3 move disk 1 from peg 2 to peg 3
Here is Project Euler's problem 1:
Find the sum of all the multiples of 3 or 5 below 1000.
Solve this problem in one line of Python using a list comprehension.
Solve Project Euler's problem 6 in one line of Python using list comprehensions.