number=input('Enter a number? ')
print(number)
I want to convert this in single statement.
number=input('Enter a number? ')
print(number)
I want to convert this in single statement.
Just you can use int()
:
number=int(input('Enter a number? '))
print(number)
Otherwise, to be fool-proof, use try..except:
while True:
try:
number=int(input("Enter a number ? "))
break
except ValueError:
print("Please input a vaild number !!")