求平均成绩(python3解释器)
输入学生姓名;
依次输入学生的三门科目成绩;
计算该学生的平均成绩, 并打印;
平均成绩保留一位小数点;
计算该学生语文成绩占总成绩的百分之多少?并打印。eg: 78%;
name = input(‘学生姓名:’)
chinese = float(input(‘语文成绩:’))
math = float(input(‘数学成绩:’))
engish = float(input(‘英语成绩:’))
总成绩
sumscore = chinese+math+engish
平均成绩
avgscore = sumscore/3
求百分比
chinesepercent = (chinese/sumscore) * 100
print(’%s的平均成绩为:%.2f’ %(name,avgscore))
print(‘语文成绩占总成绩的:%.2f%%’ %(chinesepercent)
1 and 2
两个条件同时满足 就返回True
只要有一个条件不满足,就返回False
or
1 or 2
两个条件只要满足一个 就返回True
两个条件都不满足,就返回False
“”"
python_score = 60
c_score = 50
if python_score >= 60 and c_score >=60:
print(‘考试通过’)
else:
print(‘考试不通过’)
.
输入年、月,输出本月有多少天。合理选择分支语句完成设计任务。
[root@localhost mnt]# vim nianyue.py
[root@localhost mnt]# cat nianyue.py
year = int(input('please put year: '))
month = int(input(‘please put month:’))
if month1 or month3 or month5 or month7 or month8 or month10 or month12:
print(‘this month have 31days’)
elif month4 or month6 or month9 or month11:
print(‘this month have 30days’)
else:
if ((year%40 and year%100!=0) or (year%400==0)):
print(‘this month have 29days’)
else:
print(‘this month have 28days’)
[root@localhost mnt]#
效果展示
[root@localhost mnt]# /usr/local/python3/bin/python3 nianyue.py
please put year: 2018
please put month:3
this month have 31days
[root@localhost mnt]# /usr/local/python3/bin/python3 runnian.py
please put year:2008
is runyear
[root@localhost mnt]# /usr/local/python3/bin/python3 nianyue.py
please put year: 2008
please put month:2
this month have 29days
根据用于指定月份,打印该月份所属的季节。
提示: 3,4,5 春季 6,7,8 夏季 9,10,11 秋季 12, 1, 2 冬季
[root@localhost mnt]# vim jijie.py
[root@localhost mnt]# cat jijie.py
month = int(input('please put a Num: '))
if month3 or month4 or month5:
print(‘chunji’)
elif month6 or month7 or month8:
print(‘xiaji’)
elif month9 or month10 or month11:
print(‘qiuji’)
elif month12 or month1 or month2:
print(‘dongji’)
根据效果展示
[root@localhost mnt]# /usr/local/python3/bin/python3 jijie.py
please put a Num: 5
chunji
[root@localhost mnt]# /usr/local/python3/bin/python3 jijie.py
please put a Num: 9
qiuji