Python | Basic coding exercise | Show the Hogwarts house colours for a user

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

You can learn how to do this exercise if you attend the course listed below!

Software ==> Python  (25 exercises)
Version ==> Latest version
Topic ==> Basic coding  (3 exercises)
Level ==> Harder than average
Classroom ==> Python programming
Online ==> Python programming

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

This exercise asks you to write a program which displays your Hogwarts house colours given your input house name.  Here's what a typical output should look like when you run the program:

Typical output

Ravenclaw: the forgotten Harry Potter house.

 

First create a new program file called Sorting Hat.py, and set a variable to hold the house name typed in by a user.

To make it easier to test the value of your variable add .lower() to the end of it (this will convert whatever the user types in into lower case).

Before the next part of the exercise you'll need to know the Hogwarts house colours, which are:

House Colours
gryffindor Scarlet and yellow, of course
hufflepuff Yellow and black
ravenclaw Blue and bronze
slytherin Green and silver (ssss)

Write an if ... elif ... else block which sets the value of another variable to the correct house colours (if the house typed in by your user doesn't exactly match any of the ones listed above, your program should set your colours to Not known).

Unknown house message

Use the else clause of your if condition to return this message if a user types in an unknown house name.

 

Remember that you can use \n within a text string to throw a carriage return to get the new lines shown in our example.

Test that your program works by trying a few different house names, then save and close it. 

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post