"> ");
100%
LESSONS & TOPICS

Exercises Calculations and in-built functions

Exercises Calculations and in-built functions


 

 

Exercises lesson 3

Exercise 1

Let’s use Pythagoras theorem to calculate the length of the hypotenuse of a right-angled triangle where the other sides have lengths 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 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 to 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..