python第三次上机课代码

4-9:

ans = 0
for i in range(41):
    tmp = i * 2 + (40 - i) * 4
    if tmp == 90:
        ans = i
        break
print("鸡有{}只,兔子有{}只".format(ans, 40-ans))

4-10

x = eval(input("请输入需要因式分解的数:"))
print("{}=".format(x), end=' ')
for i in range(2, x):
    if x % i == 0 and x != 0:
        while x % i == 0:
            print(i, end='')
            x = x//i
            if x % i == 0 :
                print("*", end='')
        if x != 1:
            print("*", end='')

4-11:

x = 100
ans = 0
times = 1
while times <= 10:
    ans = ans + x + x/2
    times += 1
    x = x/2
print("共经过{}米".format(ans))

4-12:

down = 1
up = 2
tmp = 0
ans = 0
for i in range(20):
    ans = ans + up / down
    up = up + down
    down = up
print("前20项之和为:{}".format(ans))

4-13:

ans = 0
for i in range(1,21):
    tmp = 1
    for j in range(1, i+1):
        tmp = tmp * j
    ans = ans + tmp
print(ans)

4-14:

x = input("请输入一个串:")
print(len(x))
print(x[::-1])

4-15:

x = eval(input("请输入一个数x:"))
a = x % 10
b = x // 10 % 10
c = x // 1000 % 10
d = x // 10000 % 10
if a == d and c == b:
    print("该数是一个回文数!")
else:
    print("该数不是回文数!")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值