Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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


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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading