I Haz Codes

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Menu
elif and else

Learn

The final part of IF statements is to look at how we can make use of elif and else. Else allows us to do something when the condition is false. Elif allows us to daisy chain multiple if statements together but only allowing one of them to be true.

Try

You need to write a program which will say what grade you got in a test. The grades can be found in the table below. You need to write a program which will say what grade you got in a test. The grades can be found in the table below.

GradeScore
A85
B76
C63
D52
E44
F33
U<33
Table showing sample grade data for the task.

Challenge

Enter the code below. This program will ask the user a simple maths question and then should check to see if the answer is correct or not. You need to complete the code by adding the if statement. It should –

Display “correct” if they enter the correct answer

Display “incorrect” if they enter an incorrect answer

Test

Try the following quiz to test your knowledge.

Tasks to try

Challenge task

Comments are closed.

Information