-1

Cycle through two arrays in parallel by adding : between them during print

Arrays

NOME = ['CARLOS','JOAO','PEDRO']

IDADE ['30','25','22']

GOAL

CARLOS:30
JOAO:25
PEDRO:22

SCRIPT

rows = len(NOME)
for i in range(rows):
    print(str(NOME[i]+":"+IDADE))

ERROR

TypeError: cannot concatenate 'str' and 'list' objects

Luis Henrique
  • 701
  • 15
  • 36
  • 4
    You missed taking indexed value from second array `NOME[i]+":"+IDADE` should be `NOME[i]+":"+IDADE[i]`. – makozaki Oct 04 '19 at 17:04

1 Answers1

1

How about:

rows = len(NOME) for i in range(rows): print(str(NOME[i]+":"+IDADE[i]))

Khaldoon Masud
  • 300
  • 2
  • 4