What season is this month in?
Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.
Watch this video to learn about the new concepts shown in the program:
Questions to think about with this program to check your understanding:
In line 25: `print(“Month”, month, “is in the”, season)` why is the word month written twice in this line, but it is only output once?
“Month” in double quotes is a string, it is the actual word, “Month”. In contrast, month without the double quotes is a variable: an area in memory to hold data that can change. This is holding the name of the month the user inputs. E.g. “May”. As we want the word “Month” followed by the name of the month to be output we need both in the statement.
Change the program so that:
Enter the number of the month: 5
Month 5 is in the Spring
Use these resources to learn about new commands for this level and to help you meet the success criteria.
Provides an alternative structure to `if elif else` and is used in situations where there are more than two possibilities. There are also more advanced uses of match that make it more useful than `if`. You need to be using Python 3.10 or higher to use the match command. Don’t forget the colon at the end of the match statement.
Is the value for the match command. Possibilities for the value can be separated with pipe characters: `|`. You can have as many case statements as you need. Don’t forget the colon at the end of the case statement.
An underscore is a special condition that is the same as `else`. It captures anything else that was not matched by the previous case statements. Don’t forget the colon at the end of the case statement.
Run the unit tests below to check that your program has met the success criteria.
Enter the month: 1
Month 1 is in the Winter
Enter the month: September
Month September is in the Autumn
Enter the month: 8
Month 8 is in the Summer