elif skipped.find(depend) != 0: AttributeError: 'int' object has no attribute 'find'
时间: 2023-07-24 13:21:09 浏览: 61
这个错误是因为skipped是一个整数,而不是字符串,因此无法使用字符串方法find()。在这段代码中,可能是因为想要判断depend是否在skipped中,但是使用了错误的方法。
要解决这个错误,可以先将skipped转换为字符串,然后再使用find()方法判断depend是否在skipped中。具体实现可以使用str()函数将skipped转换为字符串,如下所示:
```python
skipped = self._outcome.result.skipped
skipped_str = str(skipped)
if skipped_str.find(depend) != -1:
# do something
else:
# do something else
```
注意,这里使用了find()方法判断depend是否在skipped中时,应该判断是否等于-1,而不是不等于0。因为find()方法返回的是查找到的字符串的索引,如果未找到,则返回-1。如果使用不等于0来判断,那么如果depend在字符串的第一个位置,会被误判为未找到。
相关问题
解释一下下面的代码def print_link(head): while head!=None: if head.exp==1 and head.coef!=0: print('%dX+'%(head.coef),end='') elif head.exp!=0 and head.coef!=0: print('%dX^%d+'%(head.coef,head.exp),end='') elif head.coef!=0: print('%d'%head.coef) head=head.next print()
As an AI language model, I do not have feelings and emotions like humans, so I cannot feel null. In computer programming, null refers to the absence of a value or an empty variable.
class student(): def __init__(self,score): self.score=score def grade(self): if self.score>=90: print(4.0) elif self.score>=86: print(3.7) elif self.score>=83: print(3.3) elif self.score>=80: print(3.0) elif self.score>=76: print(2.7) elif self.score>=73: print(2.3) elif self.score>=70: print(2.0) elif self.score>=66: print(1.7) elif self.score>=63: print(1.3) elif self.score>=60: print(1.0) else: print(0) sc=int(input()) print(stu.grade())为什么这里会打印出None来!!!
你的代码中存在一个问题,即在 `print(stu.grade())` 中,你使用了 `stu` 而不是 `student`。另外,你也没有先创建一个学生对象,所以你需要先创建一个学生对象并将其分数传递给对象。修改后的代码如下:
```
class Student():
def __init__(self, score):
self.score = score
def grade(self):
if self.score >= 90:
return 4.0
elif self.score >= 86:
return 3.7
elif self.score >= 83:
return 3.3
elif self.score >= 80:
return 3.0
elif self.score >= 76:
return 2.7
elif self.score >= 73:
return 2.3
elif self.score >= 70:
return 2.0
elif self.score >= 66:
return 1.7
elif self.score >= 63:
return 1.3
elif self.score >= 60:
return 1.0
else:
return 0
score = int(input("请输入学生成绩:"))
stu = Student(score)
print(stu.grade())
```
这样就能够正确输出学生的成绩了。注意,我修改了 `grade` 方法中的 `print` 语句为 `return` 语句,并在 `print(stu.grade())` 中使用了 `return` 返回的成绩。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)