problem with functions

0

Good morning colleagues could tell me what error my code has when executing it always what is in the "except ValueError" I have already tried doing it in other ways and it does not give me this is my code:

#-*coding:utf-8-*-

'''7. Construir una función que reciba como parámetro un carácter y retorne el código ASCII
asociado a él'''

def codigo_ascii(valor):
    valor=int(valor)

    return(valor)

def main():
    try:
        letra=str(input("Digite un caracter :"))
        caracter=codigo_ascii(letra)
        print(caracter)

    except ValueError:
        print("El valor digitado no puede ser numerico")

if __name__=='__main__':
    main()
    
asked by Andress115 20.11.2018 в 17:39
source

1 answer

1

As @Eugeni Bejan said, the following should suffice:

def main():
    try:
        letra=str(input("Digite un caracter: "))
        caracter=ord(letra)
        print(caracter)

    except ValueError:
        print("El valor digitado no puede ser numerico")

if __name__=='__main__':
    main()
    
answered by 27.12.2018 в 18:56