1.Print multiplication table
#99乘法表
for i in range(1,10):
sum=""
for j in range(1,i+1):
a=str(j)+"*"+str(i)+"="+str(i*j)+"\t"
sum+=aprint(sum)
update:
for i in range(1,10):
sum=""
for j in range(i,10):
a=str(i)+"*"+str(j)+"="+str(j*i)+"\t"
sum+=a
else:
sum=" "*i*8+sum
print(sum)
2.Print a Rhombic
#打印菱形
for i in range(1,8,2):
a=(8-i)//2
print(" "*a+"*"*i)
for j in range(5,0,-2): #???如何简写
a=(7-j)//2
print(" "*a+"*"*j)
update:
for i in range(-3,4):
if i > 0:
i = i
else:
i = -i
print(" "*i+"*"*((4-i)*2-1))
update:
Print a lightning
for i in range(-3,4): #如何精简
if i == 0:
print(7*"*")
elif i < 0:
i = abs(i)
print(" "*abs(i)+"*"*(4-abs(i)))
else:
print(" "*3+"*"*(4-abs(i)))
update:
Print Two Triangles with Common Vertex
n=int(input("please enter the number about height of the triangle:"))
for i in range(1-n,n):
if i == 0:
print(" "*(4-abs(i))+"*")
else:
print(" "*(4-abs(i))+"*"*(abs(i)*2+1))
3.Print Fibonacci Series within 100
#打印100以内斐波那契数列
a=1
b=1
print(a,b,sep='\n')
for i in range(5):
a+=b
if a>100:
break
print(a)
b+=a
if b>100:
break
print(b)
4.Calculate the Nth/101st of the Fibonacci series
#打印斐波那契数列第N位
number=int(input("please enter a number:"))
a=1
b=1
if 0<number<=2:
print("the "+str(number)+" of the Fibonacci series is 1")
if number>2:
n=(number-1)//2
for i in range(n):
a+=b
b+=a
if number%2!=0:
print("the "+str(number)+" of the Fibonacci series is "+str(a))
else:
print("the "+str(number)+" of the Fibonacci series is "+str(b))
other people's:
update:
n=int(input(">>>"))
a=0
b=1
print(b)
for i in range(n):
c=a+b
print(c)
a=b
b=c
5.Calculate all the prime number within 100000
count=0
for i in range(1,100000,2):
a=int(i**0.5+1)
for j in range(3,a):
if i % j == 0:
break
else:
count+=1
print(i)
print("num:"+str(count))