Exercise Answers

To get the most out of these tutorials, you should almost never use this page unless you get really stuck or you just want to check you did something correctly. A lot of programming is about trying things out and working through problems, so don’t deny yourself the learning opportunity that process provides but looking at answers too quickly!

Answers for Introduction Tutorial

Answers for Variables Tutorial

Problem: Let’s suppose that you have a dinosaur zoo. In your zoo, you have two T-Rexes, three Unaysaurus, and five Spinosaurus

[2]:
# 1. Create variables for the number of each dino you have called `my_trexes`, `my_unas`, and `my_spinos`.
my_trexes = 2
my_unas = 3
my_spinos = 5

# 2. Now use those variables to calculate how many total dinosaurs you have.
my_trexes + my_unas + my_spinos
10
[3]:
# 3. Oh no! One of your t-rexes got out and ate an Unaysaurus. Decrease the value of `my_unas` by one.

my_unas = my_unas - 1

# 4. Double oh no! Your T-Rexes were male and female, and they just had a baby! Increase you number T-Rexes by one!

my_trexes = my_trexes + 1

# 5. Sadly, one of your Spinosauruses died of old age. :( Decreases your count of Spinosauruses by one.

my_spinos = my_spinos - 1

# 6. How many dinos do you have now? You've probably lost count of all these changes, but thankfully they're all stored in variables, so you can just add them all up!

my_trexes + my_unas + my_spinos
9
[ ]: