试编写程序实现以下功能:1、接收由用户输入的分数(假设为整数)2、根据以下规则输出相应的内容:如果分数大于等于90且 小于等于100,输出"Excellent' 如果分数大于等于80且小于90,输出'Good' 如果分数大于等于 60且小于80,输出'Passed' 如果分数大于等于 且小于60,输出'Failed'如果分数大于100或者 小于0,输出"Error'
时间: 2023-06-06 17:04:26 浏览: 156
以下是实现该功能的Python代码:
```
score = int(input("请输入分数:"))
if score >= 90 and score <= 100:
print("Excellent")
elif score >= 80 and score < 90:
print("Good")
elif score >= 60 and score < 80:
print("Passed")
elif score >= 0 and score < 60:
print("Failed")
else:
print("Error")
```
如果你有任何关于代码的问答,我会非常乐意为你解答。
相关问题
用python3.4试编写程序实现以下功能: 1、接收由用户输入的分数(假设为整数) 2、根据以下规则输出相应的内容: 如果分数大于等于90且小于等于100,输出'Excellent' 如果分数大于等于80且小于90,输出'Good' 如果分数大于等于60且小于80,输出'Passed' 如果分数大于等于0且小于60,输出'Failed' 如果分数大于100或者小于0,输出'Error'(20分)
以下是实现上述功能的Python代码:
```
score = int(input("请输入一个整数分数:"))
if score >= 0 and score < 60:
print("Failed")
elif score >= 60 and score < 80:
print("Passed")
elif score >= 80 and score < 90:
print("Good")
elif score >= 90 and score <= 100:
print("Excellent")
else:
print("Error")
```
这个程序首先接收用户输入的一个整数分数,然后根据分数的大小输出相应的内容。如果分数大于等于90且小于等于100,输出'Excellent';如果分数大于等于80且小于90,输出'Good';如果分数大于等于60且小于80,输出'Passed';如果分数大于等于0且小于60,输出'Failed';如果分数大于100或者小于0,输出'Error'。
试编写程序,完成以下功能:应用函数编写程序实现:由用户输入一个整数,计算n!
以下是使用Python编写的程序,实现计算n!的功能:
```python
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
n = int(input("请输入一个整数:"))
result = factorial(n)
print("{}! = {}".format(n, result))
```
程序中定义了一个factorial函数,用于计算n的阶乘。如果输入的n为0,则直接返回1;否则递归调用自身,计算n*(n-1)*(n-2)*...*1。最后,程序输出计算结果。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.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)