I am writing a python program that requests a name and age. Store that data in a List. After the user has entered data, request that the user enters 'y' or 'n' to continue. If they enter 'n', print the list of names and ages figures to the screen. If they enter 'y', repeat the first step.
This is what I have done.
keepAsking = True
# Keep looping for as long as keepAsking is equal to true
while(keepAsking == True):
stdName = input(" Name: ")
ageRecord = int(input("Age: "))
name_array = list()
age_array = list()
name_array.append(stdName)
age_array.append(ageRecord)
# Create and set checkContinue
checkContinue = True
# Keep looping for as long as checkContinue is equal to true
while (checkContinue == True):
# Ask the user if they wish to continue, and store it in doContinue
doContinue = input("Continue? ")
# Did they enter yes?
if (doContinue.lower() == "yes") :
# If so, stop asking if they want to continue, but keep asking
# everything else. Thus checkContinue is made false, but keepAsking
# remains true
checkContinue = False
# Did they enter no?
elif (doContinue.lower() == "no") :
# If so, stop asking if they want to continue ...
checkContinue = False
print (name_array)
print (age_array)
This is what its meant to show
Name: Faith Wisdom
Age: 28
Continue? [y/n] y
Name: Mitchell Train
Sales: 15
Continue? [y/n] n
Faith Wisdom 28
Mitchell Train 15
but with what I wrote, it's showing
Name: Faith Wisdom
Age: 28
Continue? [y/n] y
Name: Mitchell Train
Sales: 15
Continue? [y/n] n
Mitchell Train 15
The first entry is not saving in the list