Question
Hello! I am currently working on a program to take an email address, password and user name from a user and display them. I am
Hello! I am currently working on a program to take an email address, password and user name from a user and display them. I am stuck on getting my getUsername() function to do anything. I get a blank list. My program is not finished yet, i have to add a third condition that would exit the menu so bear that in mind please! I added the print(token_emailAddress) and it prints a blank list. what am i doing wrong?
def main():
# Declare variables
choice = ''
repeat = 'y'
emailAddress = ''
username = ''
password = ''
#initiates three blank lists
emailAddressList = []
passwordList = []
usernameList = []
# Display program header
print('Login Verification Program')
print('--------------------------')
while repeat == 'y':
# Display program menu
print(' 1. Enter new login credentials')
print('2. Display login credentials')
print('3. Exit program')
choice = input('Enter selection: ')
if choice == '1':
emailAddressList.append(getEmailAddress())
passwordList.append(getPassword())
username = getUsername(emailAddress)
usernameList.append(username)
print('Credentials Accepted!')
if choice == '2':
displayCredentialsReport(emailAddressList,passwordList,usernameList)
# define the getEmailAddress function
def getEmailAddress():
# asks the user to input their email address
isValid = False
emailAddress = input('Enter your email address:')
while isValid != True:
# tests to see if there are two characters in the email address
if '.' not in emailAddress:
print('Your email address is invalid!')
emailAddress = input('Please re-enter:')
isValid = False
elif '@' not in emailAddress:
print('Your email address is invalid!')
emailAddress = input('Please re-enter:')
isValid = False
else:
isValid = True
#function returns email address
return emailAddress
# define the get password function
def getPassword():
# define local variables
i = 0
sp = 0
u = 0
l = 0
isValid = False
#print the initial message
print('NOTE: Passwords must be at least 8 characters in length and contain at least one uppercase letter and one number.')
password = input('Enter your password:')
# begins the while loop for the function
while isValid != True:
# tests to see if the password has less than 8 characters
if len(password) < 8:
print('Your password is invalid!')
password = input('Please re-enter:')
isValid = False
break
# when condition passes, we move on to testing the contents of the password
else:
for c in password:
# tests for te digit
if c.isdigit():
i = 1
# tests for special characters
elif c=="$" or c=="#" or c=="@":
sp = 1
elif c == c.upper():
# tests for an upper case`
u = 1
# tests for a lower case
elif c == c.lower():
l = 1
else:
# exits if statement if all conditions are met
continue
# if all of the branches of the if statement are met, the following appends the
# valid password to the list of passwords
if i == 1 and l == 1 and sp == 1 and u == 1:
isValid = True
break
else:
print('Your password is invalid!')
password = input('Please re-enter:')
continue
# returns the password and the password list
return password
def getUsername(emailAddress):
token_emailAddress = emailAddress.split('@')
username = token_emailAddress[0]
print(token_emailAddress)
return username
def displayCredentialsReport(emailAddressList,passwordList,usernameList):
# Display report header
c=0
print('Login Credential Report')
print('----------------------- ')
print('Email Address ' + '\t' + 'Password ' + '\t' + 'Username')
print('------------- ' + '\t' + '-------- ' + '\t' + '--------')
while c < range(len(usernameList)):
print(emailAddressList[c] + '\t' +passwordList[c] + '\t' + usernameList[c])
c+=1
if __name__ == '__main__':
main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started