2015-05-04 185 views

回答

0

你可以嘗試將字符串轉換成int和捕獲異常:

def is_number(s): 
    try: 
     int(s) 
     return True 
    except ValueError: 
     return False 

ask = input('please enter a number: ') 

while not is_number(ask): 

    print ("no, a number!") 
    print('') 
    ask = input('please enter a number: ') 
相關問題