Python Exercises lesson 3

Write the code in an IDLE window or use the python window at the bottom of the page.

Exercise 1

Before I solve the exercise..

I remember it or learn it! The square of a number is the result of multiplying that number by itself. For example, the square of 3 is 3 x 3 = 9. The square root of a number is the opposite of squaring that number. It is a value that, when multiplied by itself, gives the original number. For example, the square root of 9 is 3, because 3 x 3 = 9.

I remember it or learn it! The Pythagorean Theorem is a formula that relates to the sides of a right triangle. A right triangle is a triangle with one angle that measures 90 degrees. The theorem states that the square of the length of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the lengths of the other two sides. In mathematical notation, this can be written as c^2 = a^2 + b^2, where c is the length of the hypotenuse, and a and b are the lengths of the other two sides.

Let’s use Pythagoras’ theorem to calculate the length of the hypotenuse of a right-angled triangle where the other sides have lengths of 3 and 4 meters.

  1. Create variables called “b” and “c” and assign them the values of the sides with known lengths.
  2. Write a mathematical expression to calculate the length of the hypotenuse
  3. (REMEMBER: “a-squared equals b-squared plus c-squared”).
  4. Create a variable “a” that equals the result of the calculation.
  5. Print the value of the variable “a”.

After doing that please replace the assignments at the begging of your solution by using the function “input”. Explain the difference.

Exercise 2

Write a program in Python to find and display the area of a rectangle (length x height). Ask the user the height and length from the keyboard with the “input” instruction.

Exercise 3

Write a program that asks the user for their name and age, turns their age into days, and prints an appropriate message, e.g.

John, you are 11344 days old

Click the following link to get access to more exercises..