from sys import stdoutfor i in range(4):
for j in range(2 - i + 1):
stdout.write(" ")
for k in range(2 * i + 1):
stdout.write("*")
print("\n")
for i in range(3):
for j in range(i + 1):
stdout.write(" ")
for k in range(4 - i * 2 + 1):
stdout.write("*")
print("\n")```
有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13,。。。。。求这个数列20项之和
i = 2
j = 1
Sum = 0s = []
for k in range(10):
san = i / j
i, j = i + j,i
# S.append(san)
Sum += san
# 收集它们,看看是否准确s.append("%d/%d"%(i , j))
print(Sum)
print(s)
求1+2!+3!+4!…….20!
j = 1
He = 0for i in range(1,21):
sum = j * i
j = sum
He += sum
print(j)
# print(sum)
print(He)
给一个不多于5位的正整数,要求:一,求他是几位数,逆序打出各位数字。
# 转为字符串的形式更好处理
number = int(input("input your number:"))
Number = str(number)
L = int(len(Number))
LU = []
for i in range(L):
LU.append(Number[L-i-1])
print(LU)
一个五位数,判断是不是回文数,即12321是回文数
number = int(input("input your number:"))
Number = str(number)
ifNumber[0] == Number[4] and Number[1] == Number[3]:
print("这是一个回文数")
else:
print("这不是一个回文数")
判断输入的数是不是回文数
number = int(input("input your number:"))
MUM = str(number)
Nu = int(len(MUM))
# 左右各占一半的长度为
Half = int(Nu-1)/2if Nu % 2 != 0:
for i in range(1, Half+1):
# 才是中间的那个不用加上1,然后依次判断左右是否相等# 中间那个数是MUM[Half]# i最后停止于4# 保证循环次数为Halfif MUM[Half - i] == MUM[Half + i] and i == Half:
print("这是一个回文数")
print(":这不是回文数")
else:
print(":这不是回文数")