学习地址:
t=https://study.163.com/course/courseMain.htm?courseId=1005913008
特将课后作业记录如下
一、实现体脂率公式计算
gender = input('请输入您的性别(男性填写1或女性填写2):')
print(gender)
waistline = input('请输入您的腰围(cm):')
print(waistline)
weight = input('请输入您的体重(kg):')
print(weight)
gender = int(gender)
waistline = float(waistline)
weight = float (waistline)
a = waistline*0.74
if gender == 1:
b = weight*0.082+44.47
else:
b = weight*0.082+34.89
lipweight = a - b
BMI = lipweight/weight
print('您的体脂率为:','%.2f%%'%(BMI*100))
二、采用for语句实现九九乘法表
for row in range(1,10):
for column in range(1,10):
if column <= row:
print('%s*%s=%s'%(column,row,column*row),end=' ')
else:
print('')
break
三、计算水仙花数
for n in range(100,1000):
a = n//100
b = (n-a*100)//10
c = n-a*100-b*10
if (a**3+b**3+c**3) == n:
print(n,'是水仙花数')
老师还给出了另一种解法参考:
for value in range(100,1000):
x = int(str(value)[0])
y = int(str(value)[1])
z = int(str(value)[2])
if value == (x**3 +y **3 +z **3):
print(u"%s是水仙花数"%value)
网友评论