In this project, you will write functions that use iteration to solve problems.Part 0, 2 points: In class, we write the function countdown_alternative
. Make sure you code this one up correctly with the while loop. (It's very similar to the function in the book.) Tester.
Part 1, 2 points: Copy the sequence
function from the book, which we talked about in class.Tester.
Part 2, 2 points: Write the print_monkeys
function from class. This one should just print out monkey
on n
lines:
>>> print_monkeys(3)
monkey
monkey
monkey
Tester.Part 3, 2 points: Write print_monkey_mountain
, which prints n
lines, each one with one more monkey in it:
>>> print_monkey_mountain(4)
monkey
monkeymonkey
monkeymonkeymonkey
monkeymonkeymonkeymonkey
Remember to test the zero-case:>>> print_monkey_mountain(0)
>>>
Tester.Part 4, 2 points: Write round_up_to_square
, which takes an integer and rounds up to the lowest square integer greater than or equal to the input. Here are some examples:
>>> round_up_to_square(4)
4
>>> round_up_to_square(5)
9
Notice that this is fruitful, so it should return and not print, which you can check by storing the return value in a variable:>>> x = round_up_to_square(5)
>>> print(x)
9
>>>
Tester.Part 5, 1 points: Write def square_root_from_guess(number, guess, delta=.0001)
, which uses Newton's Method to approximate the square root of number. The square of the value it returns should be within delta of the given number. Tester.
Part 6, 1 points: A proper function for the previous problem would not include guess as a paramter. Write a wrapper function, my_square_root
, for square_root_from_guess
. It should still include an optional delta parameter. Tester.
Submitting your Project:
Make sure all your code is in a file labelled with your user name (everything before the @ in your school email address) followed by _projects.py
all in snake_case. (For example, my file name would be: kburke_projects.py
.) It's very important to name your file correctly in order for me to grade it. Make sure your code runs, then upload it to the project on Canvas. (Don't submit code that doesn't run; you won't earn any points!) Your code should include solutions to all non-zero-point problems from Project 0 onwards. If there is already a file up on Canvas, delete that before uploading the new version or make sure your new file replaces that. (Sometimes Canvas adds a number after the file name. Don't worry about that, because it's something (freaking annoying) you don't have control of. I have a script that automatically deletes that.)