We learned how to use dictionaries and apply it to this activity, including functions and lists as well.
Tag Archives: python
Battleship! – Lab #7
In this code academy activity, we learn how to recreate the board game “Battleship” on Python using functions, conditionals, lists. This activity was certainly challenging as there are room for error in indentations and listing the conditionals in the correct order, so it definitely took lots of trail and error before arriving at the right sequence.
Date and Time – Lab #6
Fruitful Functions – Lab #5
Fermat’s Last Theorem
In number theory, Fermat’s Last Theorem states that no three positive integers a, b, and c can satisfy the equation an + bn = cn for any integer value of n greater than two. The cases n = 1 andn = 2 were known to have infinitely many solutions.
First problem.
1. Write a function named check_fermat that takes four parameters—a, b, c and n and that checks to see if Fermat’s theorem holds. If n is greater than 2 and it turns out to be true that an+ bn = cn the program should print, “Fermat was wrong!” Otherwise the program should print, “No, that doesn’t work.”
2. Write a function that prompts the user to input values for a, b, c and n, converts them to integers, and uses check_fermat to check whether they violate Fermat’s theorem.
Second problem.
In addition to the first problem, your code should let user make input and therefore to produce result.