Programming Pandit

c/c++/c#/Javav/Python


Latest Update

Tuesday, November 17, 2020

Python program to display ASCII code of a character and vice versa by G Krishna Chauhan

Source Code


var=True while var:

choice=int(input("Press-1 to find the ordinal value of a character \nPress-2 to find a character of a value\n"))

if choice==1:

ch=input("Enter a character : ") print(ord(ch))

elif choice==2:

val=int(input("Enter an integer value: ")) print(chr(val))

else:

print("You entered wrong choice")

 

print("Do you want to continue? Y/N") option=input()

if option=='y' or option=='Y': var=True

else:

    var=False



OUTPUT


 Press-1 to find the ordinal value of a character 

Press-2 to find a character of a value

1

Enter a character : D

68

Press-1 to find the ordinal value of a character 

Press-2 to find a character of a value

2

Enter an integer value: 4



Press-1 to find the ordinal value of a character 

Press-2 to find a character of a value

2Press-1 to find the ordinal value of a character 

Press-2 to find a character of a value

1

Enter a character : D

68

Press-1 to find the ordinal value of a character 

Press-2 to find a character of a value

2


No comments:

Post a Comment