Discuss / Python / 练习

练习

Topic source

AL

#1 Created at ... [Delete] [Delete and Lock User]

test 4 报错后修改

def get_grade(self):
        if self.score < 0 or self.score > 100:
            raise ValueError

报错:B!=A

if self.score >= 60 and self.score < 80:
            return 'B'

综上,修改版本⬇

def get_grade(self):
        if self.score < 0 or self.score > 100:
            raise ValueError
        if self.score >= 60 and self.score < 80:
            return 'B'
        if self.score >= 80:
            return 'A'
        return 'C'

101>80,raise error如果在80判断后面,会报错,应该在前面

lldhsds

#2 Created at ... [Delete] [Delete and Lock User]

网站留言板,代码粘贴进去的时候排版还是好的,发送出去后排版就乱了。你是什么格式写答案了?


  • 1

Reply