why I can't print one by one in the python list?

Question:


allData = []
tanggaldata= []
while True:
    name = input("input your name (if done input DONE) : ")
    tanggal = input("input your date (if done input DONE) : ")
    if name == "DONE" or tanggal == "DONE":
        break
    elif name != "DONE":
        allData.append(name)
        tanggaldata.append(tanggal)
        continue

for data in allData:
    for tanggaldatas in tanggaldata :
        print(data +" lahir pada tanggal "+ tanggaldatas)

When i want to print for each but there is a double print instead like :
enter image description here

Asked By: Amongus

||

Answers:

You are printing doubles because you have a loop inside of a loop. You don’t need the second loop

for tanggaldatas in tanggaldata :

For every person you are already getting a name and date so there will always be the same amount of both. Instead use a for loop with a counter till the length one of the arrays so you can get the element at the same index.
ie.

for i in range(len(allData)):
   print(allData[i] +" lahir pada tanggal "+ tanggaldata[i])
Answered By: KP101Coder