Registrations Closing Soon for DevOps Certification Training by CloudxLab | Batch Starts on 18th April

  Enroll Now

Calculations with Variables

Now we know how to assign the value to a variable. Let's see how to use variables in the code and how variables are useful. Let's calculate the area of a rectangle with height as 50 and width 40. The formula for the area of a rectangle is -

Area of rectangle = height * width

Let's write the code. Define two variables height and width and give them the value of 50 and 40 respectively and then apply the formula

height = 50
width = 40
area_of_rectangle= height * width

Run the above code in the Jupyter notebook on the right-hand side. It should give print area as 2000

  • Modify the value of height variable to 60
  • Modify the value of width variable to 40
  • Calculate the area of rectangle with updated height and width and store it in the new_area_of_rectangle variable
  • Print the new area. It should print the area as 2400

No hints are availble for this assesment

Answer is not availble for this assesment

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...