2
I’m taking the Python 3 course on video and I’m in exercise n° 82. Even though my code and the teacher’s code are almost identical, mine is making the mistake not all Arguments converted During string formatting. My code is this:
a = list()
b = list()
c = list()
while True:
a.append(input('Digite um número:'))
r = str(input('Deseja continuar: [S/N]:')).upper().strip()
if r == 'N':
break
for i, v in enumerate(a):
print(v)
print(i)
if v % 2 == 0:
b.append(v)
elif v % 2 != 0:
c.append(v)
print(f'A lista de números digitados é: {a}')
print(f'Desses números, {len(b)} deles são pares. Estes são {b}')
print(f'Desses números, {len(c)} deles são impares. Estes são {c}')
Pycharm makes no mistake. Where did I go wrong?
By the way, my version of Python is 3.6
And the error is happening on line 12:if v % 2 == 0:
Just one detail: the result of
numero % 2
, for any number, it will always be 0 or 1. Then theelif
is unnecessary and can be exchanged for aelse
:if v % 2 == 0: b.append(v) else: c.append(v)
– hkotsubo