Good evening I made a poll/poll code, but it’s not computing the vote when it’s said by name instead of number

Asked

Viewed 48 times

0

I made a line of code to do a search on a street to find out which channel people watch, and I put it to compute the vote by channel number or channel name, but it only computes the votes made by number and not by name, can give me a light ?

def pesquisa_audiencia (canal):
    global canal_cultura, canal_globo, canal_band, canal_record

    if canal.isalpha():
        if canal== 'Encerrar':
            print('Encerrado')
            print_resultados()

    elif canal.isalnum():
        if canal == '2' or canal == 'Cultura' or canal == '4' or canal == 'Globo' or canal == '7' or canal == 'Band' or canal == '9' or canal == 'Record':
            if canal == '2':
                canal_cultura +=1
            elif canal == 'Cultura':
                canal_cultura +=1
            elif canal == '4':
                canal_globo +=1
            elif canal == 'Globo':
                canal_globo +=1
            elif canal == '7':
                canal_band +=1
            elif canal == 'Band':
                canal_band +=1
            elif canal == '9':
                canal_record +=1
            elif canal == 'Record':
                canal_record +=1
     
        

def print_resultados():
    global canal_cultura, canal_globo, canal_band, canal_record

    print('Porcentagem de Audiência por canal:\n')
    print('Canal 2:' + str(canal_cultura))
    print('Canal 4:' + str(canal_globo))
    print('Canal 7:' + str(canal_band))
    print('Canal 9:' + str(canal_record))


    exit()

if __name__ == '__main__':
    canal_cultura = 0
    canal_globo = 0
    canal_band = 0
    canal_record = 0

    while True:
        canal = input('Qual canal estão assistindo neste momento em sua casa?')
        pesquisa_audiencia(canal)

1 answer

0


Which python version of Windows are you using? Take a look at this link: The difference in input() and raw_input functions()

If using Python 2, use raw_input instead of input.

def pesquisa_audiencia (canal):
    global canal_cultura, canal_globo, canal_band, canal_record

    if canal == "Encerrar":
        print('Encerrado')
        print_resultados()

    if canal == '2' or canal == 'Cultura':
        canal_cultura +=1
    elif canal == '4' or canal == 'Globo':
        canal_globo +=1
    elif canal == '7' or canal == 'Band':
        canal_band +=1
    elif canal == '9' or canal == 'Record':
        canal_record +=1     
    else:
        print("Voto nao computado")

def print_resultados():
    global canal_cultura, canal_globo, canal_band, canal_record

    print('Porcentagem de Audiencia por canal:')
    print('Canal 2 - ' + str(canal_cultura)) + " votos"
    print('Canal 4 - ' + str(canal_globo)) + " votos"
    print('Canal 7 - ' + str(canal_band)) + " votos"
    print('Canal 9 - ' + str(canal_record)) + " votos"
    exit()

if __name__ == '__main__':
    canal_cultura = 0
    canal_globo = 0
    canal_band = 0
    canal_record = 0

    while True:
        canal = raw_input('Qual canal estao assistindo neste momento em sua casa?')
        pesquisa_audiencia(canal)

If you are using Python 3, give us more information about the errors.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.