The ‘else’ and ‘elif’ Statements Ex.


1) Let's say we want to make a prototype program that checks if a user entered a valid ID number. The ID numbers in our hypothetical system are supposed to be 8 characters long. Write a program that uses the if-elif-else idiom to determine if the length of a string is too short, too long, and just right. Print specific feedback to the user that tells them which problem they have, if any, and confirms their entry if they have the right length. This requires some elements of previous units.

In [1]:
# user entry
user_input = "8675309"

# length we want 
id_number_len = 8 

### You do the rest! :) ### 

2) Recall how you could test each condition to make sure they all work as desired. Implement the test.

Let's assume we're writing a prototype for a password checker. The program will have a variable that is got from a user (by magic for now, but we will learn how to do this) and a true password to compare it to. Your job is to implement the comparison and print a message saying "access granted" if it matches and "Uh, Uh, Uh, didn't say the magic word" if it doesn't.