Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Q1
- def skip_add(n):
- """ Takes a number x and returns x + x-2 + x-4 + x-6 + ... + 0.
- >>> skip_add(5) # 5 + 3 + 1 + 0
- 9
- >>> skip_add(10) # 10 + 8 + 6 + 4 + 2 + 0
- 30
- """
- "*** YOUR CODE HERE ***"
- # Q6
- def gcd(a, b):
- """Returns the greatest common divisor of a and b.
- Should be implemented using recursion.
- >>> gcd(34, 19)
- 1
- >>> gcd(39, 91)
- 13
- >>> gcd(20, 30)
- 10
- >>> gcd(40, 40)
- 40
- """
- "*** YOUR CODE HERE ***"
- # Q7
- def hailstone(n):
- """Print out the hailstone sequence starting at n, and return the
- number of elements in the sequence.
- >>> a = hailstone(10)
- 10
- 5
- 16
- 8
- 4
- 2
- 1
- >>> a
- 7
- """
- "*** YOUR CODE HERE ***"
- # Q8
- def fibonacci(n):
- """Return the nth fibonacci number.
- >>> fibonacci(11)
- 89
- >>> fibonacci(5)
- 5
- >>> fibonacci(0)
- 0
- >>> fibonacci(1)
- 1
- """
- "*** YOUR CODE HERE ***"
- # Q9
- def paths(m, n):
- """Return the number of paths from one corner of an
- M by N grid to the opposite corner.
- >>> paths(2, 2)
- 2
- >>> paths(5, 7)
- 210
- >>> paths(117, 1)
- 1
- >>> paths(1, 157)
- 1
- """
- "*** YOUR CODE HERE ***"
Advertisement
Add Comment
Please, Sign In to add comment