ASCII Value Finder - Problem
Write a program that takes a character as input and displays its ASCII value. The program should also be able to take an ASCII value and display the corresponding character.
Your task is to implement a solution that can handle both conversions:
- Given a character, find its ASCII value
- Given an ASCII value, find the corresponding character
The input will specify which operation to perform using a mode parameter:
- If
modeis "char_to_ascii", convert the character to its ASCII value - If
modeis "ascii_to_char", convert the ASCII value to its character
Input & Output
Example 1 — Character to ASCII
$
Input:
mode = "char_to_ascii", input_value = "A"
›
Output:
65
💡 Note:
The character 'A' has ASCII value 65. Using ord('A') or equivalent gives us 65.
Example 2 — ASCII to Character
$
Input:
mode = "ascii_to_char", input_value = "97"
›
Output:
a
💡 Note:
ASCII value 97 corresponds to lowercase letter 'a'. Using chr(97) gives us 'a'.
Example 3 — Special Character
$
Input:
mode = "char_to_ascii", input_value = " "
›
Output:
32
💡 Note:
The space character ' ' has ASCII value 32, which is commonly used in text processing.
Constraints
- Input character must be within ASCII range (0-127)
- Mode must be either "char_to_ascii" or "ascii_to_char"
- For char_to_ascii: input must be a single character
- For ascii_to_char: input must be a valid integer string
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code