# Various Exception statement exercises.
print('Check If A String Is A Number?')
def is_number(this_str='') -> bool:
"""
Check if a String is a Number.
:param this_str: String, any string to check.
:returns: True/False.
:rtype: boolean
"""
value = False
try:
float(this_str)
except (ValueError, TypeError):
print(f'The String "{this_str}" is NOT a Number!')
else:
print(f'The String "{this_str}" IS a Number.')
value = True
return value
is_number('Dinder')
is_number('14')
is_number('28.76')
print('--------------------------------------------------')
Runs the entire script above. Open your Console Window in Inspect Code to view the output of the script above.
A prompt popup will ask you for various input() commands.
Client-side execution via Pyodide · No server · Full stdlib · numpy, pandas, matplotlib available via micropip
Mobile users will want to use this method. Copy snippets or the entire script from above. You may also copy this script exactly as it is shown and you can run it on your own machine using the Command-Line Interface (CLI).