def main(): score = int(input('输入分数:\n')) #**********SPACE********** if score ________________ 90: grade = 'A' elif score >= 60: #**********SPACE********** grade = ________________ #**********SPACE********** ________________ grade = 'C' #**********SPACE********** print('%d 属于 %s' % (score,________________)) if __name__ == '__main__': main()
时间: 2023-07-01 14:24:27 浏览: 106
以下是填空的代码:
```python
def main():
score = int(input('输入分数:\n'))
if score >= 90:
grade = 'A'
elif score >= 60:
grade = 'B'
else:
grade = 'C'
print('%d 属于 %s' % (score, grade))
if __name__ == '__main__':
main()
```
程序的功能是根据用户输入的分数来判断其等级。程序首先获取用户输入的分数,并将其保存在变量score中。然后,程序使用if-elif-else语句来判断分数的等级。如果分数大于等于90分,则等级为A;如果分数大于等于60分,则等级为B;否则,等级为C。最后,程序输出分数和等级。
相关问题
题目:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学 用A表示,60-89分之间的用B表示,60分以下的用C表示。 --------------------------------------------------------- 注意:除要求填空的位置之外,请勿改动程序中的其他内容。 ------------------------------------------------------''' def main(): score = int(input('输入分数:\n')) #**********SPACE********** if score ________________ 90: grade = 'A' elif score >= 60: #**********SPACE********** grade = ________________ #**********SPACE********** ________________ grade = 'C' #**********SPACE********** print('%d 属于 %s' % (score,________________)) if __name__ == '__main__': main()
答案:可以使用以下代码实现:
```
def main():
score = int(input('输入分数:\n'))
grade = 'A' if score >= 90 else ('B' if score >= 60 else 'C')
print('%d 属于 %s' % (score, grade))
if __name__ == '__main__':
main()
```
在给定的代码框架中,需要在空白处填写代码,使用条件运算符的嵌套来判断成绩等级。首先判断成绩是否大于等于90分,如果是,则成绩等级为A;如果不是,则进入下一个判断,判断成绩是否大于等于60分,如果是,则成绩等级为B,否则成绩等级为C。最后将成绩等级输出即可。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)