Untitled

 avatar
unknown
python
a year ago
2.0 kB
3
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 (familyName, mainName, birthday):
    namePart = ""
    numberPart = 0

    namePart = mainName + familyName[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 welcome():
    print("Welcome!")

# -------------------------------------------------------------------
# Main program
# -------------------------------------------------------------------
# =====> Call the welcome procedure before taking input from the user

welcome()

# Get last name and first name from the user
lastName = input ("Enter your last name: ")
firstName = input ("Enter your first name: ")

# =====> Convert last name and first name to lowercase after they
#        are inputted by the user
lastName = lastName.lower()
firstName = firstName.lower()

# Get date of birth from the user
dob = input ("Enter your date of birth (ddmmyyyy): ")

# =====> Check that only the digits 0 to 9 appear in the date of birth
if dob.isdigit() and len(dob) == 8:
    # =====> Call the makeID() function, if the date of birth is valid
    myID = makeID(lastName, firstName, dob)
    print(myID)
else:
    print("Date of birth invalid.")
Editor is loading...
Leave a Comment