Untitled
unknown
plain_text
a year ago
2.1 kB
4
Indexable
# ------------------------------------------------------------------- # Global variables # ------------------------------------------------------------------- lastName = "" firstName = "" dob = "" myID = "" # ------------------------------------------------------------------- # Subprograms # ------------------------------------------------------------------- # =====> Change the names of the local variables to distinguish them # from the global variables with the same name def makeID (surname, name, birthday): namePart = "" numberPart = 0 namePart = surname + name[0] # Letter part # =====> Correct the logic error caused by using the int() function # in the number part calculation rather than using a function # that returns the ASCII value of the character for character in birthday: numberPart = numberPart + ord (character) yourID = namePart + str (numberPart) return (yourID) # =====> Add a procedure, with no parameters, to display a # welcome message for the user def greeting(): print("Welcome!") # ------------------------------------------------------------------- # Main program # ------------------------------------------------------------------- # =====> Call the welcome procedure before taking input from the user greeting() # Get last name and first name from the user surname = input ("Enter your last name: ") name = input ("Enter your first name: ") # =====> Convert last name and first name to lowercase after they # are inputted by the user surname=surname.lower() name=name.lower() # Get date of birth from the user birthday = input ("Enter your date of birth (ddmmyyyy): ") # =====> Check that only the digits 0 to 9 appear in the date of birth birthday.isdigit() # =====> Call the makeID() function, if the date of birth is valid if length<=9: myID = makeID (surname, name, birthday) print (myID) # =====> Tell the user, if the date of birth is invalid if length>9: print("You can only have 0 to 9 digits in your birthday.")
Editor is loading...
Leave a Comment