2
I’d like to know what role the function plays str()
on line 33(code does not work without this function, gives this error: Typeerror: Unsupported format string passed to list.format)
jogadores = dict()
pontos = list()
while True:
jogadores['Nome'] = str(input('Nome do jogador: '))
quant_parti = int(input(f'Quantas partidas {jogadores["Nome"]} jogou? '))
for c in range(0, quant_parti):
pontos.append(int(input(f' => Na {c}° partida, quantos gols {jogadores["Nome"]} fez? ')))
jogadores['Gols'] = pontos[:]
jogadores['Total'] = sum(pontos)
pontos.clear()
time.append(jogadores.copy())
jogadores.clear()
while True:
opcao = str(input('Deseja continuar? [S / N] ')).upper()
if opcao in 'SN':
break
else:
print(f'\033[1;31m[ ERROR ]\033[m Tente somente S ou N.')
if opcao == 'S':
print('-=-=-='*10)
if opcao == 'N':
print('-=-=-='*10)
break
print('Cód', end=' ')
for k in time[0].keys():
print(f'{k:>12}', end='')
print()
print('-=-=-='*10)
for i, v in enumerate(time):
print(f'{i}', end=' ')
for value in v.values():
print(f'{str(value):>12}', end=' ')
print()
print('<<< FIM >>>')```
The answer below explained what the
str
, but to understand becausef'{value:>12}'
does not work in all cases (as happened in your code, whenvalue
is a list), see this question. And for the record, another alternative is to usef'{value!s:>12}'
, forvalue!s
is equivalent to callingstr(value)
.– hkotsubo