2
Can someone help me with this code?
I have two problems: The first is the error mentioned in the title and the second is the vector of the function, which does not receive attribution (when I went to debug the compiler, I realized that U was not receiving any values).
I’m new to programming, don’t be surprised if there’s some barbaric error ;)
def calPercent(nvJ,tV):
U = [0]*23
for i in range(23):
if nvJ[i]!= 0:
U[i] = nvJ[i]/tV*100
return U
V = [0]*23
P = [0]*23
voto = int(input("Numero do jogador (0=fim): "))
while voto!=0 :
if voto<1 or voto>23 :
print "Informe um valor entre 1 e 23 ou 0 para sair!"
else:
V[voto-1]+=1
voto = int(input("Numero do jogador (0=fim): "))
P = calPercent(V,sum(V))
print "Foram computados",sum(V),"votos"
print "Jogador,Votos,%"
for i in range(23):
if V[i]!=0 :
print "%d,%d,%d%" %(i+1,V[i],P[i])
for i in range(23):
if V[i] == max(V):
print "O melhor jogador foi o numero %d, com %d votos, correspondendo a %d% do total de votos" %(i+1,V[i],P[i])
Since you debugged, can you report the error line? As for barbaric errors, I would only recommend that you give descriptive names to their variables. No U, V, nvJ etc.
– Pablo Almeida