#!/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
提交
取消