CJCoding With Joseph

Missing Dictionary Key

A Dictionary<string, int> maps names to ages (Alice=30, Bob=25). Read a name and print its age with ages[name]. Looking up a key that is not present throws a KeyNotFoundException — catch it and print exactly Name not found. Use top-level statements with try/catch.

Input Alice prints: 30
Input Zoe prints: Name not found

Expected Output:

30
Topics:
Exceptions
📥 Auto-Input:
Alice\n
This input is automatically fed to your program's stdin
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (cw, cr, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.