- 输入学生姓名
- 依次输入学生的三门科目成绩
- 计算该学生的平均成绩,并打印
- 平均成绩保留一位小数
- 计算语文成绩占总成绩的百分比,并打印
name = input("学生姓名:")
Chinese = float(input("语文成绩:"))
Math = float(input("数学成绩:"))
English = float(input("英语成绩:"))
# 总成绩
SumScore = Chinese + Math + English
# 平均成绩
AvgScore = SumScore / 3
ChinesePercent = (Chinese / SumScore) * 100
print('%s 的平均成绩为%.1f' % (name, AvgScore))
print('语文成绩占总成绩的%.2f%%' % ChinesePercent)
-判断闰年
-用户输入年份,判断是否为闰年?
- 能被400整除的是闰年,能被4整除但是不能被100整除的是闰年
year = int(input('Year:'))
if (year % 4 == 0 and year % 100 != 0) \
or (year % 400 == 0):
print('%s是闰年' %year)
else:
print('%s不是闰年' %year)
1.从控制台输入你要出的拳 —石头(1)/剪刀(2)/布(3)
2.电脑随即出拳
3.比较胜负
import random
# a = random.randint(1,10)
# print(a)
#1.从控制台输入要出的拳
player = int(input('请输入您要出的拳:石头1/剪刀2/布3:'))
#2.电脑出拳
computer = random.randint(1,3)
print(computer)
#3.比较胜负
if ((player == 1 and computer == 2) \
or (player == 2 and computer == 3) \
or (player == 3 and computer == 1)):
print('玩家胜利~')
elif player == computer:
print('平局')
else:
print('玩家失败~')
1.输入年、月,输出本月有多少天
2004 2
29天
2010 4
30天
year = int(input(' 年份:'))
num=int(input(' 请输入一个月份:'))
if num in (1,3,5,7,8,10,12):
print('31天')
elif num ==2:
if (year%100!=0 and year%4==0 or num%400==0):
print('29天')
else:
print('28天')
else:
print("30天")
用户输入月份,判断这个月是哪个季节
month = int(input('Month:'))
if month in [3,4,5]:
print('春季')
elif month in [6,7,8]:
print('夏季')
elif month in [9,10,11]:
print('秋季')
elif month in [12,1,2]:
print('冬季')
else:
print('输入不合法')
有1,2,3,4四个数字
求这四个数字能生成多少个互不相同且无重复数字的三位数
a = random.randint(1,50)
print(a)