dimanche 5 décembre 2021

If input is empty then assign None

If input is empty or zero it should get None.

This is what has been attempted:

The int is necessary.

number = int(input('Type an integer: ') or None )
number = number if number != 0 else None 
print(number)

How to avoid this issue:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Aucun commentaire:

Enregistrer un commentaire