# Week 6 practice problems, by chaynes@indiana.edu def message(score, goal): """ Print the message "You lose" when the score is less than 90% of the goal, the message "Close, but no prize" when the score is less than, but within 10% of, the goal, the message "You win" if the score is over the goal, but by less than 100 points, and the message "You are awesome!" when the score is 100 points or more over the goal. (Avoid using unnecessarily complicated logic in your solution.) """ #. #. #. #. #. #. #. #. def min3(x, y, z): """ Return the minimum of x, y, and z. >>> min3(3, 1, 5) 1 >>> min3(0, 8, 7) 0 >>> min3(1, 0, -5) -5 >>> """ # Use the built-in min function, but only with two arguments #. #. #. #. def min3_without_min(x, y, z): """ Return the minimum of x, y, and z. >>> min3_without_min(3, 1, 5) 1 >>> min3_without_min(0, 8, 7) 0 >>> min3_without_min(1, 0, -5) -5 >>> """ # Do not use any built-in functions #. #. #. #. #. #. #. #. #. def inorder(x, y, z): """ Return a boolean value indicating if the arguments are in ascending or descending order. >>> inorder(1, 3, 3) True >>> inorder(1, 1, 5) True >>> inorder(0, 3, -1) False >>> inorder(1, 0, 2) False >>> """ #... def left_justify(n, s): """ Returns a string with the characters of s followed by enough spaces for the returned string to be of length n. >>> left_justify(5, 'abc') 'abc ' >>> """ #... def powers(n): """ Print a table of the first n powers of two, with left justification, with columns 2 and 4 characters wide, and one space between columns. >>> powers(10) 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024 >>> """ #. #. #. #. def center(n, s): """ Returns a string of length n containing the characters of s with space characters on either side. The number of spaces added on one side should differ by at most 1 from the number on the other side. >>> center(4, '*') ' * ' >>> # ' * ' would also be correct """ #. #. def print_star(num_spaces): """ Prints a line the given number of spaces, followed by a star. >>> print_star(3) * >>> print_star(0) * >>> """ #... def print_big_greater_than(size): """ Print a greater than sign using 2*size+1 lines with a star on each line, and the number of spaces before the star changing by two with each line. >>> print_big_greater_than(1) * * * >>> print_big_greater_than(3) * * * * * * * >>> """ #. #. #. #. #. #. #. #. def print_big_less_than(size): """ Print a greater than sign using 2*size+1 lines with a star on each line, and the number of spaces before the star changing by two with each line. >>> print_big_less_than(1) * * * >>> print_big_less_than(3) * * * * * * * >>> """ #. #. #. #. #. #. #. #. def print_fibonacci(n): """ Print the first n Fibonacci numbers, separated by spaces, and ending with a new line. The Fibonacci numbers are an infinite sequence of numbers beginning 1, 1, 2, 3, 5, 8, and so on, in which each number after the first two is the sum of the previous two (in the example 5=2+3 and 8=3+5). Assume n is at least 2. >>> print_fibonacci(5) 1 1 2 3 5 >>> print_fibonacci(20) 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 >>> Fibonacci (pronounced fib-o-nachi) numbers appear in a number of places in the geometry of nature, including shell spirals and sunflowers. And as you can see, they grow fast (exponentially). """ #. #. #. #. #. #. #. #. #. #.