My superhero

superhero

Learning Objectives


In this challenge we are learning how to use variables to store the properties of a superhero. Some of our variables will be used to store text (string) such as the name of our super hero. Some variables will be used to store numbers, either whole numbers (integers) or numbers with a decimal place (reals/floats).

Once we have stored all our properties of our superhero we will use the print command in Python to print a full description of our superhero.

Using variables


Look at the example below to see how text (string) and numbers (integers or reals) are stored using variables.

Have you noticed the use of “speech marks” when storing a string?

Step #1


Use the trinket below to store the name, location, gender, name of the enemy, super powers of your superhero. Dont forget the use of “speech marks”.

Step #2


Now save the speed, age and strength of your superhero using numerical values. You will not need to use speech marks.

Step #3

We will now use the print command to display a description of our superhero on screen.

We will combine statements such as “My superhero is called ” and variables (such as name) to create a clear description of our superhero. To do this we will use the + operator.

Tip:


When combining two strings or a statement and a string variable we use the + operator. For instance:

When combining a string or a statement with a numerical variable (integer or real) we have to cast (convert) this number into a string using the str() function. For instance:

Your Challenge


Complete your code to create a complete description of your superhero. For instance:

My name is Batman and I live in Gotham City. I am male and my enemy is The Joker.

Extension:


Can you think of additional properties to describe your superhero? For instance the colours of their costume, their height, their weight, etc.

Create more variables to store these new properties and complete your description of your superhero.

Share Button
Posted in Computer Science, Python - Beginner, Python Challenges Tagged with:

Our Latest Book

Follow this blog