作业3:
健康计划
用户输入身高(m),体重(kg) 计算公式:BMI = 体重 / 身高^2
BMI < 18.5:过轻 18.5≤ BMI <24:正常 24 ≤ BMI <27:过重 27 ≤ BMI < 30:轻度肥胖
30 ≤ BMI < 35:中度肥胖 BMI ≥ 35:重度肥胖
a=float(input("输入你的身高:"))
b=float(input("输入你的体重:"))
c=b/a**2
if c<18.5:
print("过轻")
elif c>=18.5 and c<24:
print("正常")
elif c>=24 and c<27:
print("过重")
elif c>=27 and c<30:
print("轻度肥胖")
elif c>=30 and c<35:
print("中度肥胖")
elif c>=35:
print("重度肥胖")
else:
print("输入有误")
作业4:打印如下图案:
直角三角形
a=int(input("输入你要选择的层数:"))
b=1
for b in range(a+1):
print("*"*b)
b+=1
等腰三角形
layer = int(input("请输入您要打印的层数:"))
for i in range(1, layer + 1):
space_nums = layer - i
star_nums = 2 * i - 1
print(" "*space_nums + "*"*star_nums)
倒立的等腰三角形
layer = int(input("请输入您要打印的层数:"))
for i in range(layer, 0, -1):
space_nums = layer - i
star_nums = 2 * i - 1
print(" "*space_nums + "*"*star_nums)
作业6:
让用户输入一个月份,判断这个月是哪个季节?假定3到
4月是春季,5到8月是夏季,9到10是秋季,11、12、1、2
月是冬季
a=int(input("输入一个季节:"))
if a==3 and a==4:
print(f"{a}是春季")
elif a>=5 and a<=8:
print(f"{a}是夏季")
elif a==9 and a==10:
print(f"{a}是秋季")
elif a==1 and a==2 and a==12 and a==11:
print(f"{a}是冬季")
else:
print("超出范围")
作业7:
提示用户输入用户名,然后再提示输入密码,如果用户名
是“admin”并且密码是“88888”,则提示正确,否则,如果
用户名不是admin还提示用户用户名不存在,如果用户名是
admin则提示密码错误。
a=input("输入用户名:")
b=input("输入密码:")
if a=="ztl" and b=="5201314":
print("你已进入田家齐的系统")
elif a != "ztl":
print("该用户进入了错误的系统")
elif a=="ztl" and b!="5201314":
print("密码错误")
作业8:有一些四位数,百位数字都是3,十位数字都是6,并且它们既能被2整除,又能被3整除,求这样的四位数中最大的和最小的两数各是几?
index = 1000
while index < 10000 :
a = index //100%10
b = index //10%10
if a==3 and b==6 and index%2==0 and index%3==0:
print(index)
index += 1
作业10:用户输入两个数a、b。如果a能被b整除或a加b大于1000,则输出a;否则输出b。
a=int(input("输入第一个数:"))
b=int(input("输入第二个数:"))
if b//a==0 or a+b>1000:
print("输出a")
else:
print("输出b")
作业11:输入赵本山的考试成绩,显示所获奖励
成绩==100分,爸爸给他买辆车
成绩>=90分,妈妈给他买MP4
90分>成绩>=60分,妈妈给他买本参考书
成绩<60分,什么都不买
a=int(input("输入成绩:"))
if a==100:
print("田家齐给他买辆车")
elif a>=90:
print("张天乐给他买随身听")
elif a<90 and a>=60:
print("田帅帅给他买本参考书")
elif a<60:
print("大漂亮给他一嘴巴子")
else:
print("无效成绩")
作业13:输入三边的长度,求三角形的面积和周长(海伦公式)
a=int(input("输入长度:"))
b=int(input("输入长度:"))
c=int(input("输入长度:"))
if (a+b>c and a+c>b and b+c>a):
e=a+b+c
d=(a+b+c)/2
s=(d*(d-a)*(d-b)*(d-c)) **0.5
print(f"周长是{e},面积是{s}")
作业19:输入一个年份,判断该年是否是闰年
a=int(input("输入一个年份:"))
if a%4==0 and a%100!=0 or a%400==0:
print(f"{a}是闰年",)
else:
print(f"{a}是平年",)
作业16:猜数字游戏(使用random模块完成)
电脑随机一个范围内的数,用户输入数据判断,
如果数大了,提供”数大了“
成功之后,加上用户是否继续功能
import random
computer = random.randint(1, 100)
while True:
my = int(input("请输入您要猜的数:"))
if my == computer:
print("恭喜您,猜对了")
choice = input("您是否继续?结束请输入(n/N),按任意键继续:")
if choice == "N" or choice == "n":
break
else:
computer = random.randint(1, 100)
elif my > computer:
print("对不起,猜大了")
else:
print("对不起,猜小了")
print("GAME OVER!!!")
作业17:猜拳游戏:石头、剪刀、布的游戏
import random
while True:
computer = random.randint(1, 3)
user = int(input("请输入您要出的拳(1:石头、2:剪刀、3:布):"))
if user == computer:
print("平局")
elif (user == 1 and computer == 2) or (user == 2 and computer == 3) or (user == 3 and computer == 1):
print("你赢了")
else:
print("电脑赢了")