第三章课后习题3.1-3.5

3.1 重量计算

s, yearup = 50, 0.50
for i in range(10):
    s += yearup
    print("{:.3f}".format(s))
    print("{:.3f}".format(0.165*s))

50.500  8.332           51.000  8.415         51.500  8.498            52.000  8.580          52.500  8.662               

53.000  8.745           53.500  8.828         54.000  8.910            54.500  8.992          55.000  9.075

 

3.2 天天向上
 dayup, dayfactor, day = 1.0, 0.01, 1
while day < 365:
    for i in range(7):
        if i%7 in[0,1,2,3]:
            dayup *= (dayfactor + 1)
        day += 1
print("{:.2f}".format(dayup))

7.92

 

3.4 回文数判断
n = input()
b = n[::-1]
if n == b:
    print("该数字是回文数")
else:
    print("该数字不是回文数")

 

3.5 田字格的输出
 for i in range(11):
    if i%5 == 0:
        str1 = "+" + "+".center(9, "-") + "+"
        str2 = " ".join(str1)
        print(str2)
    else:
        print("|" + "|".center(19) + "|")
posted @ 2025-03-23 15:10  与尔5  阅读(13)  评论(0)    收藏  举报