If-Else Statements

2 / 4

Sometimes it is useful to check several conditions. For example, if a user inputs a new password and the length of the password should be checked:

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 a double indentation in the code. A more clean solution 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")

Else-if

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

Congratulations!

You passed the !

Welcome!

Would you like a guided tour on how to use Vibewise?

Your email has been verified!