🏅 Exercises ¶
Here are some exercises you can do to practice. Open this document in Google Colab and write your Python code in the cells below.
Temperature conversion ¶
Declare a variable named
celsius
with some temperature value.
Convert this value into Fahrenheit using the formula
$$ \left(\frac{9}{5} \cdot \text{celsius} \right) + 32 $$
and store the output into a variable called
fahrenheit
and print it.
Answer:
If
celsius
is 42, then
fahrenheit
should be 107.6.
Swapping Values ¶
Declare two variables
a
and
b
and assign one as
5
and the other
8
.
Swap the values of
a
and
b
without using a third variable.
Hint:
Think about how you can use arithmetic operations to manipulate the values of
a
and
b
in a way that allows you to swap them without using a third variable.
Consider the properties of addition and subtraction.
Increasing value ¶
Declare one variable
bank_account
and assign the value
1
.
Next, add
325
to the this variable without creating any new variable.
Hint: You can always go to a memory address, change the value, and then keep it there.