更改

跳转至: 导航搜索

使用Python判断学生成绩

添加1,509字节, 2022年11月20日 (日) 14:17
创建页面,内容为“# -*- coding:UTF-8 -*- # ============================================================ # # Filename pythonlesson1.py # Version: 1.0 # Author: ytyzx # Create Date: 202...”
# -*- coding:UTF-8 -*-
# ============================================================
#
# Filename pythonlesson1.py
# Version: 1.0
# Author: ytyzx
# Create Date: 2022/11/20
# Update Date: 2022/11/20
# 基础学习python
#
# ============================================================
# 定义函数,可以正确分辨小数和负数
def is_number(s):
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False


inputscore = input('请输入分数: ')
if is_number(
inputscore
): #isdigit函数只能辨别正整数,对小数和负数的判断都出现了错误。 isnumeric() :是否所有字符均为数值字符,包括Unicode数字、双字节全角数字、罗马数字、汉字数字,不包括小数。
stuscore = eval(
inputscore
) # eval()会去掉字符串最外层的引号,然后当做Python语句执行[mark:语句or表达式,应该是表达式!],直观理解是:看起来像数字的字符串变成数字了
if stuscore < 0 or stuscore > 100 or stuscore % 0.5 != 0:
print('请输入正确的分数')
elif 100 >= stuscore >= 80:
print('成绩优秀')
elif 80 > stuscore >= 60:
print('成绩良好')
elif 60 > stuscore >= 40:
print('成绩及格')
else:
print('不及格')
else:
print('此处请输入数字')
1,138
个编辑

导航菜单