#!/usr/bin/env python#coding:UTF-8import randomnumber = random.randint(1,101)guess=0while True:num_input =input("please input one integer that is 1 to 100:")guess += 1if not num_input.isdight():print("please input interger")elif int(num_input) < 0 or int(num_input) >= 100:print("the number should be in 1 to 100")else:if number==int(num_input):print("you are right")breakelif number > int(num_input):print("your number is more less")elif number < int(num_input):print("your number is more bigger")else:print("I will not work")我運行隨便輸入范圍內的數字 結果報錯說if not num_input.isdight():AttributeError: 'str' object has no attribute 'isdight' 怎么回事 謝謝了
1 回答

慕絲7291255
TA貢獻1859條經驗 獲得超6個贊
#!/usr/bin/env python #coding:UTF-8 import random number = random.randint( 1 , 101 ) guess = 0 while True : num_input = raw_input ( "please input one integer that is 1 to 100:" ) guess + = 1 if not num_input.isdigit(): #是isdigit print ( "please input interger" ) elif int (num_input)< 0 or int (num_input)> = 100 : print ( "the number should be in 1 to 100" ) else : if number = = int (num_input): print ( "you are right" ) break elif number> int (num_input): print ( "your number is more less" ) elif number< int (num_input): print ( "your number is more bigger" ) else : print ( "I will not work" ) |
添加回答
舉報
0/150
提交
取消