1
How can I associate a range of values from 1 to 6 to each of the options in the OS menu that I have in the list? My idea is that when I type three times the number 1 for example, this counts as three votes for the Windows Server option, so in the end I can print it as the most voted poll.
I thought I’d try to solve it with a dictionary, but I’d have to type in the name of the operating system as a key every time I wanted to compute a vote
votos = []
valor = 0
mais_votado = []
maisvotado = 0
maiorpercent = 0
print('Qual o melhor sistema operacional para uso em servidores?''\n''As respostas são:''\n'
'1 - Windows Server''\n'
'2 - Unix''\n'
'3 - Linux''\n'
'4 - Netware''\n'
'5 - Mac OS''\n'
'6 - Outro')
valor = int(input('Insira o número correspondente a alguma das opções:'))
while 0 < valor <= 6:
valor = int(input('Insira o número correspondente a alguma das opções:'))
votos.append(valor)
if valor > 6:
valor = int(input('Valor inválido,insira um valor válido:'))
total = len(votos)
for i in range(total):
if votos.count(i) > 1:
mais_votado.append(i)
for i in mais_votado:
if i > maisvotado:
maisvotado = i
for i in votos:
percent = (i * 100)/sum(votos)
if percent > maiorpercent:
maiorpercent = percent
Thank you so much for the help,I managed to solve using this solution with even dictionaries,ended up getting more practical
– Marco Aurélio Lopes Júnior