9 9乘法表
for i in range(1,10):
for j in range(1,i+1):
print(j, '×', i, '=','{:<5.2f}'.format(i * j), end=' | ')
print()pingunshu
平均数
sum=0
count=0
while True:
i = int(input('请输入数值:'))
sum += 1
count += i
print('count=',count)
print('sun=',sum)
print('avr=',count / sum)
斐波那契数列
sum=1
j=1
a=0
while sum<1000000:
if j<2:
print(j,end=",")
j+=1
else:
print(sum, end=',')
a = sum - a
sum = sum + a
计算数字位数
num = int(input('请输入十亿以下数字:'))
count=0
while num is not 0:
if num>=1000000000:
print('您输入的数太大了!!!')
break
else:
a = ['个位:', '十位:', '百位:', '千位:', '万位:','十万:','百万:','千万:','亿:']
print(a[count]+str(num%10),end=' | ')
num=num//10
count+=1
print('你输入数字的位数是:', count)
扑克洗牌
import random
pokers_num=[str(i) for i in range(2,11)]
pokers_color=['黑','红','方','花']
pokers_king=['大王','小王']
pokers_str=['A','J','Q','K']
pokers=["%s%s" %(i,j) for i in pokers_color for j in pokers_num+pokers_str]+pokers_king
print(len(pokers))
random.shuffle(pokers)
print(pokers)
name1=pokers[0:51:3]
name2=pokers[1:51:3]
name3=pokers[2:51:3]
last_3=pokers[-3:]
print('name1:',name1)
print(last_3)
杨辉三角
triangle=[[1],[1,1]]
n=6
for i in range(2,n):
pre=triangle[i-1]
cur=[1]
for j in range(0,i-1):
cur.append(pre[j] + pre[j + 1])
cur.append(1)
triangle.append(cur)
print( triangle)
质数
n=int(input('请输入一个数字:'))
for i in range(2, n):
if n % i == 0:
print(n, '是和数')
print(int(n/i))
print(i)
break
elif i==(n-1):
print('质数')
print(i)