Question
The code below raises a TypeError because it compares a string to an integer:
x = "6"
if x > 3:
print("x is larger than 3")
(a) Wrap it in a try/except block that catches the TypeError and prints a helpful message.
(b) Fix the comparison by converting x to an integer before comparing.
(c) Write a function safe_compare(x, threshold) with try/except that also handles ValueError for the case x = "abc" (cannot be converted to int).