if the string is '007w', then when it tries to return '007w' as integer, i want it to return None
and print('Cannot be converted)
. But without using the Try Except ValueError:
import random
def random_converter(x):
selection = random.randint(1,5)
if selection == 1:
return int(x)
elif selection == 2:
return float(x)
elif selection == 3:
return bool(x)
elif selection == 4:
return str(x)
else:
return complex(x)
for _ in range(50):
output = random_converter('007w')
print(output, type(output))