0
Hello, people! I’m starting to learn python and decided to make a program about voting. As I do, for example, to compare the results of the votes and print that there was a tie between two candidates?
print('Votação')
print('Candidatos: ')
print('1-Candidato 1\n2-Candidato 2\n3-Candidato 3\n4-Candidato 4\n5-Candidato 5\n')
cand1 = 0
cand2 = 0
cand3 = 0
cand4 = 0
cand5 = 0
cont: int = 0
v = 0
venc = 0
voto_nulo = 0
resp = 'Sim'
while resp == 'Sim':
resp = str(input('Deseja votar? '))
if resp == 'Sim':
cont += 1
v = int(input('Digite o seu voto: '))
if (v == 1) or (v == 2) or (v == 3) or (v == 4) or (v == 5):
if v == 1:
cand1 += 1
elif v == 2:
cand2 += 1
elif v == 3:
cand3 += 1
elif v == 4:
cand4 += 1
elif v == 5:
cand5 += 1
else:
voto_nulo += 1
else:
print('\nFim da votação')
if (cand1 > cand2) and (cand1 > cand3) and (cand1 > cand4) and (cand1 > cand5):
venc = 'Candidato 1'
if (cand2 > cand1) and (cand2 > cand3) and (cand2 > cand4) and (cand2 > cand5):
venc = 'Candidato 2'
if (cand3 > cand1) and (cand3 > cand2) and (cand3 > cand4) and (cand3 > cand5):
venc = 'Candidato 3'
if (cand4 > cand1) and (cand4 > cand2) and (cand4 > cand3) and (cand4 > cand5):
venc = 'Candidato 4'
if (cand5 > cand1) and (cand5 > cand2) and (cand5 > cand3) and (cand5 > cand4):
venc = 'Candidato 5'
print('\nO total de votos foi: {}'.format(cont))
print('Votos nulos: {}'.format(voto_nulo))
print('O candidato 1 obteve {} votos'.format(cand1))
print('O candidato 2 obteve {} votos'.format(cand2))
print('O candidato 3 obteve {} votos '.format(cand3))
print('O candidato 4 obteve {} votos'.format(cand4))
print('O candidato 5 obteve {} votos'.format(cand5))
print('O candidato vencedor foi ---> {}'.format(venc))
Shit, I was already giving up on solving this program. Vlw there, mate! Helped me a lot
– Lady Pavlichenko
You are welcome. Please accept the answer if it worked.
– Rocchi