Exercises

In the same my_variables.py file which you got open

  1. Create a variable long_hair. If your hair is long set it to True, otherwise set it to False. And remember, if you bought your hair it's yours! Don't let anyone tell you different.

  2. Create a variable called goat_music and that holds your favourite song. Using either string concatenation or the format function, print a message saying that the song in goat_music is the greatest song of all time. E.g. if goat_music = "Yellow by Coldplay" then print "Yellow by Coldplay is the Greatest Song of All Time".

  3. Let's start with two variables: wheels_on_bike = 2 and wheels_on_car = 4. Create a variable called total_wheels that contains the sum of the two previous variables.

  4. Create 3 variables mysterious_question, simulation and the_answer_to_everything. the_answer_to_everything should be equal to mysterious_question + simulation. Give mysterious_question and simulation 2 numerical values that would make the_answer_to_everything equal to 42. Print the_answer_to_everything to confirm.

  5. Create 3 variables for a triangle: side1, side2 and side3. Assign them values of 3, 4 and 5 respectively. What is the perimeter of this triangle? This triangle is a right triangle, with side1 and side2 as the base and height. Can you create a variable and store its area?

Last updated