If Statements

Learn Python Programming

Tutorial

#1

Ask for two numbers. If the first one is larger than the second, display the second number first and then the first number, otherwise show the first number first and then the second.

#2

Ask the user to enter a number that is under 20. If they enter a number that is 20 or more, display the message “Too high”, otherwise display “Thank you”.

#3

Ask the user to enter a number between 10 and 20 (inclusive). If they enter a number within this range, display the message “Thank you”, otherwise display the message “Incorrect answer”.

#4

Ask the user to enter their favourite colour. If they enter “red”, “RED” or “Red” display the message “I like red too”, otherwise display the message “I don’t like [colour], I prefer red”.

#5

Ask the user if it is raining and convert their answer to lower case so it doesn’t matter what case they type it in. If they answer “yes”, ask if it is windy. If they answer “yes” to this second question, display the answer “It is too windy for an umbrella”, otherwise display the message “Take an umbrella”. If they did not answer yes to the first question, display the answer “Enjoy your day”.

#6

Ask the user’s age. If they are 18 or over, display the message “You can vote”, if they are aged 17, display the message “You can learn to drive”, if they are 16, display the message “You can buy a lottery ticket”, if they are under 16, display the message “You can go Trickor-Treating”.

#7

Ask the user to enter a number. If it is under 10, display the message “Too low”, if their number is between 10 and 20, display “Correct”, otherwise display “Too high”.

#8

Ask the user to enter 1, 2 or 3. If they enter a 1, display the message “Thank you”, if they enter a 2, display “Well done”, if they enter a 3, display “Correct”. If they enter anything else, display “Error message”.

Assessment

Now that you have completed all the challenges have a go at creating this program which sums up all of the knowledge you have learned so far. This will be marked and you will be given feedback on this piece of work so do your best!

Create a program that will display the user’s calendar for each day of the week. 

Ask the user which day of the week it is and display the correct information for each day of the week. 

On Mondays the client has a meeting every morning with the CEO at 8am. 

On Tuesdays, if the weather is not raining, the client will have lunch outside, otherwise they will eat in the office.

On Wednesdays remind the client to pick their child up from school, if their partner is at work. 

On Thursdays the client doesn’t need to be in work after 1230. 

On Fridays the client will need to be in work from 6am until 12pm, unless it is the last week of the month. If it is the last week of the month and they have got all their work done, they do not need to come into the office, otherwise they will need to be in at 8am. 

 

Check out the example Shell on the right to understand your challenge better.