Previous

If-Else Statements

5 / 6
Next

A very common pattern is an if statement directly following an else:

if len(password) < 8:
  print("Password too short")
else:
  if len(password) >= 64:
    print("Password too long")

The second if statement checks if the password exceeds the maximum length of 64. This causes an unnecessary double indentation in the code. A cleaner way is to use elif:

if len(password) < 8:
  print("Password too short")
elif len(password) >= 64:
  print("Password too long")
else:
  print("New password confirmed")
Send

Else-if

Hint
Beginner

Input a score (integer) between 0 and 100, and convert the score to a grade on scale A-F according to the following conversion table:

  • Grade A: scores 90-100
  • Grade B: scores 80-89
  • Grade C: scores 70-79
  • Grade D: scores 60-69
  • Grade E: scores 50-59
  • Grade F: scores 0-50
Help
Solve
Reset
Run
Submit
 

Test results

Test result #
Expected output
Your output

Your email has been verified!