Computer Science, asked by nirvaynikunj59, 2 days ago

W.A.P to enter single character print the previous 2 and the next 2 characters .​

Answers

Answered by Equestriadash
0

Source co‎de: [in Python]

\tt n\ =\ in put("Enter\ a\ character:\ ")\\print()\\print("The\ previous\ 2\ characters:\ ")\\print(ch r(ord(n)\ -\ 1))\\print(ch r(ord(n)\ -\ 2))\\print()\\print("The\ next\ 2\ characters:\ ")\\print(ch r(ord(n)\ +\ 1))\\print(ch r(ord(n)\ +\ 2))

Explanation:

Once the character has been entered using the \tt in put() function, we use functions \tt ch r() and \tt ord() to print the previous 2 and next 2 characters corresponding to the character entered. This is in relation to the ASCII values. ASCII values are assigned values/co‎de numbers that represent characters such as letters, numbers, special characters, etc. It helps in the electronic interpretation of what is being typed. An example has been demonstrated below.

\tt ch r(99) would return the character under co‎de 99, which is 'c'. \tt ord('c') would return the co‎de of 'c' which is 99.

Similar questions