
Coding school for kids
Code Miracles
HomeWork
•1. Let's create some variables.
•a. Create a variable called "course" and assign it the value "python".
•b. Create a variable called "rating" and assign it an integer value (anything you like).
•c. Print both variables.
•2. 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.
•a. Create variables called "b" and "c" and assign them the values of the sides with known lengths.
•b. Write a mathematical express to calculate the length of the hypotenuse (REMEMBER: “a-squared equals b-squared plus c-squared"). (b^2+c^2)^0.5
•c. Create a variable "a" that equals the result of the calculation.
•d. Print the value of variable "a".
•3. Let's take a look at some data types.
•a. Print the data type of each of the variables: a, b, c
•4. Let's investigate converting between data types.
•a. Use the "int()" built-in function to convert "a" into an integer type.
•b. Print the data type of "a" to check it worked.
•c. Now try running the following line of code: print (a + " squared equals " + b + " squared " + c + " squared." )
•d. You should get an error, do you know why?
•e. Try using the built-in "str()" (convert to string) function to fix the error.
