Types | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Types

Can anyone tell me why notas[i] are printing integer values? notas = [] qnotas = int(input('Quantidade de notas: ')) i = 0 soma = 0 while i < qnotas: k = float(input('%iª nota: '%(i+1))) notas.append(k) soma = soma + notas[i] i+=1 i = 0 while i < qnotas: print ('%iª nota: %.f'%((i+1),notas[i])) i+=1 media = soma/qnotas print('Média final: %.f'%media)

22nd May 2017, 11:14 PM
Thomas Caio Dias
Thomas Caio Dias - avatar
1 Answer
+ 1
In the final print statement do print('Média final: %f'%media) or print('Média final: {0}'.format(media)) instead of doing print('Média final: %.f'%media). The statement that you have used is removing the numbers after decimal point because you have used a '.' after the '%' symbol.
23rd May 2017, 2:03 AM
Maaz
Maaz - avatar