Oct-26-2025, 04:13 PM
Could anyone please help me and explain why my script doesn't work properly? My problem is concentrated on getting the proper user input for the last and first name functions. When the user enters an incorrect input, it will circle back to that particular input function, so that, for example, if they incorrectly enter their birthday, it will only bring up the birthday input again, and it works for the most part, but when a user enters an incorrect value for the first name function, it goes back to the last name function, which it shouldn't. I can't see why it does that. Could anyone please help me and explain why it isn't working as intended? I am at the end of my tether.
from datetime import datetime
ollum = []
def birthday(birthDate):
try:
datetime.strptime(birthDate, "%m/%d/%Y")
return True
except ValueError:
return False
def function():
loop = 'yes'
while loop == 'yes':
lName = input("Please enter your last name: ")
if lName != '':
fName = input("Please enter your first name: ")
if fName == '':
print("Invalid input!")
continue
else:
print("Invalid input!")
continue
while True:
birDay = input("Please enter your birthday: ")
if birthday(birDay):
break
else:
print("Invalid input!")
while True:
gender = input("Please enter your gender: ")
if gender.upper() not in ['M', 'F']:
print("Invalid input!")
else:
break
while True:
contNum = input("Please enter your contact number: ")
if len(contNum) != 1:
print("Invalid input!")
else:
break
ollum.append([fName, lName, birDay, gender, contNum])
loop = input('>>> ')
for i in ollum:
print('First Name:', i[0])
print('Last Name:', i[1])
print('Birthday:', i[2])
print('Gender', i[3])
print('Contact Number:', i[4])
print()
if __name__ == '__main__':
function()
