python 43~51

print("模式A")
while True:
    for i in range (1,7):
        for j in range(1, 7):
            if j <= i:
                print(j,end="\t")
        print()
    break
print()

print("模式B")
while True:
    for i in range (6,0,-1):
        for j in range(1, 7):
            if j <= i:
                print(j,end="\t")
        print()
    break
print()

print("模式C")
while True:
    for i in range (1,7):
        for j in range(6, 0,-1):
            if j <= i:
                print(j,end="\t")
            else :
                print("",end= "\t")
        print()
    break
print()

print("模式D")
while True:
    for i in range (6,0,-1):
        a = 6 - i
        print("\t" * a,end ="")
        for j in range(1, 7):
            if j <= i:
                print(j,end="\t")
        print()
    break
print()

while True :
    number = int(input("Enter a number:"))
    for i in range(0, number):
        for k in range(number  - i, 0, -1):
            print("",end="\t")
        for j in range(1,i + 1):
                print(2 ** (j-1), end="\t")
        for k in range(i + 1,0,-1):
                print(2 ** (k-1),end="\t")
        print()

count = 0
for num in range(2,1001):
    for j in range(2, num):
        if num % j == 0:
            break;
    else:
        print(num,end = "\t")
        count += 1
        if count % 8 == 0:
            print()

for j in range(10000,100001,10000):
    sum = 0
    for i in range(1,j + 1):
        sum += ((-1) ** (i + 1)) / (2 * i -1)
        PI = 4 * sum
    print("i = %d 时,  PI = %.9f"%(j,PI))

for j in range(10000,100001,10000):
    e = 1
    item = 1
    for i in range(1,j + 1):
        item *= i   #item的阶乘  item = item * i
        e += 1 / item
    print("i = %d 时,  e = %.19f"%(j,e))

for i in range(1,10001):
    sum = 0
    for j in range (1,i):
        if i % j == 0:
            sum +=j
    if i == sum:
        print(i)

 

import random
user_sum = 0
com_sum = 0
while True :
    com = random.randint(0,2)
    user = int(input("请输入石头(0),剪刀(1),布(2)所对应的数字:"))
    if user - com == -1 or user - com == 2:   # 0 - 1 ,1 - 2 or 2 - 0
        user_sum += 1
        if user_sum == 2:
            print("玩家赢了")
            break
    elif user - com == -2 or user - com == 1:  # 0 - 2 or 1 - 0, 2 - 1
        com_sum += 1
        if com_sum == 2:
            print("电脑赢了")
            break
    # else :   #   (user - com == 0)   0 - 0, 1 - 1 ,2 - 2
    #     print("平局")

 

max = 0
count = 0
while True:
    num = int(input("Enter a number (0: for end of input): "))
    if num == 0:
        break
    if num > max:
        max = num
        count = 1
    elif num == max:
        count += 1
print("The largest number is  ",max)
print("The occurrence count of the largest number is  ",count)

 

#十进制转二进制
dec_num = int(input("输入一个十进制正整数: "))  # 接受用户输入的十进制正整数
 
if dec_num == 0:
    bin_str = "0"
else:
    bin_str = ""
    while dec_num > 0:
        remainder = dec_num % 2
        bin_str = str(remainder) + bin_str
        dec_num = dec_num // 2
 
print("输出二进制字符串:", bin_str)

 

#十转十六进制
s=""
num = eval(input("请输入一个十进制数:"))
while num != 0:
    y = num % 16
    if y >= 10:
       y = chr(ord("a") + y - 10)
    s=str(y)+ s
    num = num //16
print(s)

import random
count=0
times = 1000000
for i in range(times):
  x,y=random.random(),random.random()
  if i % 10000 == 0: print("模拟投掷第",i+1,"次","当前生成的点坐标:(",x,",",y,")")
  if x < 0.5: count += 1
  if x > 0.5 and y > 0.5 and x+y < 1.5: count += 1
  if i % 10000 == 0: print("当前计算结果,奇数区域的面积为:",count/(i+1))
print(count/times)

 

 

count = 0
for y in range(2001, 2100 + 1):
    if y % 400 == 0 or y % 4 == 0 and y % 100 != 0:
        print(y, end=" ")
        count += 1
        if count % 10 == 0:
            print()

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值