0
is the following I need to make the program show the percentage of votes, only if I start the variable with zero does not give, because the program says that division by zero does not give, but if I start with 1, the account will go wrong, someone can give me a light ? the program shows how many votes had given operating system and the percentage in relation to the total.
listaWindows = []
listaUNIX = []
listaLinux = []
listaNetware = []
listaMacos = []
listaOutro = []
contW = contU = contL = contN = contM = contO = porcenW = porcenU = porcenL = porcenN = porcenM = porcenO = 0
soma = 1
while True:
print('''
1 - Windows Server
2 - UNIX
3 - Linux
4 - Netware
5 - Mac OS
6 - Outro''')
opcao = int(input("Informe a opção desejada: "))
if opcao == 0:
break
while opcao > 6 or opcao < 1:
opcao = int(input("Opção invalida, digite a opção novamente: "))
if opcao == 1:
listaWindows.append(contW)
contW += 1
porcenW = (contW / soma) * 100
if opcao == 2:
listaUNIX.append(contU)
contU += 1
porcenU = (contU / soma) * 100
if opcao == 3:
listaLinux.append(contL)
contL += 1
porcenL = (contL / soma) * 100
if opcao == 4:
listaNetware.append(contN)
contN += 1
porcenN = (contN / soma) * 100
if opcao == 5:
listaMacos.append(contM)
contM += 1
porcenM = (contM / soma) * 100
if opcao == 6:
listaOutro.append(contO)
contO += 1
porcenO = (contO / soma) * 100
soma = contW + contU + contL + contN + contM + contO
print(f'''
Votos %
Windows: {contW} {porcenW:.2f}
UNIX: {contU} {porcenU:.2f}
Linux: {contL} {porcenL:.2f}
Netware: {contN} {porcenN:.2f}
Mac {contM} {porcenM:.2f}
Outro {contO} {porcenO:.2f}''')
Thanks, that way it worked
– punkoco
@punkoco If this answer solved your problem and there is no doubt left, mark it as correct/accepted by clicking on the " " that is next to it, which also marks your question as solved. If you still have any questions or would like further clarification, feel free to comment.
– Barbetta