For Sale

for-sale

Learning Objectives


In this challenge we are learning how to use variables to store the characteristics of your house. Some of our variables will be used to store text (string) such as the street name of your house. Some variables will be used to store numbers, either whole numbers (integers) or numbers with a decimal place (reals/floats). For instance we could use a variable called numberOfBedrooms.

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

Using variables


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

streetName = "Turing Street"
typeOfHouse = "detached"
numberOfBedrooms = 3
price = 99999.99

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

Step #1


Use the trinket below to store the street name, town, type of house (terraced, semi-detached, detached, flat). Don’t forget the use of “speech marks”.

Step #2


Now save the number of bedrooms, number of reception rooms, number of floors and selling price of your house, 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 house on screen.

We will combine statements such as “My house is located on ” and variables (such as streetname) to create a clear description of our house. 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:

print("A lovely " + typeOfHouse + " located on " + streetName + ".")

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:

print("This house consists of " + str(numberOfBedrooms) + " bedrooms.")

houses

Your Challenge


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

For sale: A superb semi-detached house located on Turing Street, London. This house contains 3 bedrooms and 2 reception rooms and is organised across 2 floors. It is for sale at £1,000,000.

Extension:


Can you think of additional characteristics to describe your house? For instance number of bathrooms, etc.

Create more variables to store these new characteristics and complete your description of your house.

Challenge #2


Using if statements we can tell the computer whether to execute some lines of codes or not. Let’s create a few more variables to store whether or not your house has:

  • A front garden,
  • A back garden,
  • A swimming pool,
  • A garage,
  • etc.

Then, using if statements, we will decide whether or not to add information to our description.

For instance:

frontGarden = True
if frontGarden == True:
    print ("This house also benefits from a lovely front garden.")

Complete your code adding extra characteristics to your house and displaying a message when relevant using if statements.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4.6 / 5. Vote count: 17

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: