Hip to Be Square

The questions below are due on Sunday July 07, 2024; 10:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

Part 1

Define a function square that takes a single numeric parameter and returns its square. Submit your definition of square below:

Part 2

In the box below, define a function fourth_power that takes a single numeric parameter and returns that value raised to the fourth power. Your code should not explicitly use exponentiation or multiplication, or a loop, but rather should make use of the square function you defined above.

You may assume that square has been defined for you already in the box below (i.e., you do not need to re-paste your definition of square).

Part 3

Define a function perfect_square, that takes a single numeric argument and returns True if that argument is a perfect square, and False otherwise.

Consider 0 and 1 to be perfect squares.

Devise a plan on paper and test it with a few test cases on your own. When you are confident in your plan, implement it and test it with the Python interpreter, and debug as needed. When you are ready, upload your file below.

There are many ways of doing this, but if you feel stuck or confused, check here for a hint:

If we want to check if a float is an integer, such as 5.0, we can try casting it to an integer and checking if the two values are equal. For example, Python evaluates 5.0 == int(5.0) to be True since 5.0 and 5 are the same numeric value. But 5.1 == int(5.1) will be False since it compares 5.1 and 5.

Next Exercise: Averages

Back to exercises