2
在我的程序中,我想輸入一個應該是數字的輸入。但是,如果用戶輸入字符串,程序會返回一個異常。我希望程序以這樣的方式設置:輸入被轉換成int,然後如果字符串以外的任何其他一個int的程序打印是「停止寫作,請」。就像例如:Python處理異常
x=input("Enter a number")
if int(x)=?: #This line should check whether the integer conversion is possible
print("YES")
else #This line should execute if the above conversion couldn't take place
print("Stop writing stuff")