课程123

s=''
def Suan(a):
    if(a):
        Suan(int(a/2))
        global s
        s+=str(a%2)

def Suan2(a):
    if(a==0):
        return ""
    else:
        return Suan2(a//2)+str(a%2)
a=int(input())
Suan(a)
print(s)
print(Suan2(a))

def HeNeiTa(n,x,y,z):
    if(n>0):
        HeNeiTa(n-1,x,z,y);
        print("把{}从{}拿下来,放到{}上".format(n,x,z))
        HeNeiTa(n - 1, y, x, z);

n=int(input("请输入有多少个需要移动:"))
HeNeiTa(n,'X','Y','Z')

 代码1:

from random import *

def printIntro():
    print('该程序模拟两人之间的游戏')
    print('有两个玩家,A和B')
    print('使用概率(介于0和1之间的数字)')

def getInputs():
    a = eval(input('球员A的能力值:'))
    b = eval(input('球员B的能力值:'))
    n = eval(input('模拟比赛的场次:'))
    return a,b,n

def simNGames(n,probA,probB):
    winsA = 0
    winsB = 0
    for i in range(n):
        scoreA,scoreB = simOneGame(probA,probB)
        if scoreA >scoreB:
            winsA = winsA + 1
        else:
            winsB = winsB + 1
    return winsA,winsB

def simOneGame(probA,probB):
    scoreA = 0
    scoreB = 0
    serving = "A"
    while not gameOver(scoreA,scoreB):
        if serving == "A":
            if random() < probA:
                scoreA = scoreA + 1
            else:
                serving = "B"
        else:
            if random() < probB:
                scoreB = scoreB + 1
            else:
                serving = "A"
    return scoreA,scoreB

def gameOver(a,b):
    return a==15 or b==15

def PrintSummary(winsA, winsB):
    n = winsA + winsB
    print('\n模拟比赛数量:%d'%n)
    print('球员A获胜的场次:{0}胜率为({1:0.1%})'.format(winsA,winsA/n))
    print('球员B获胜的场次:{0}胜率为({1:0.1%})'.format(winsB,winsB/n))

printIntro()
probA,probB,n = getInputs()
winsA, winsB = simNGames(n,probA,probB)
PrintSummary(winsA, winsB)

代码2:

from math import pi,sin,cos,radians

angle = eval(input("输入发射角度(单位:度):"))
vel = eval(input("输入初始速度(单位:米/秒):"))
h0 = eval(input("输入初始高度(单位:米):"))
time = eval(input("输入时间间隔: "))
xpos = 0
ypos = h0
theta = radians(angle)#将角度转换为弧度
xvel = vel * cos(theta)#它接受一个角度(以弧度为单位)作为参数,并返回该角度的正弦值。
yvel = vel * sin(theta)
while ypos >= 0:
    xpos = xpos + time * xvel
    yvell = yvel - time * 9.8
    ypos = ypos + time * (yvel + yvell)/2.0
    yvel = yvell
print("\n行驶的距离:{0:0.1f}米.".format(xpos))
1.
a1=input()
a2=input()
tup1=(a1,a2)
print(tup1)

2.
tup1=('Niuniu','Niumei')
print(tup1)
try:
    tup1[1]= 'Niukele'
except Exception as e:
#except TypeError:
    print('The entry form cannot be modified!')

3.
l1=input().split(' ')
tup1=tuple(l1)
print(tup1[0:3])

4.
tup1=('Tom', 'Tony', 'Allen', 'Cydin', 'Lucy', 'Anna')
print(tup1)
a=input()
if a in tup1:
    print('Congratulations!')
else:
    print('What a pity!')

5.
tup1=tuple(range(1,6))
print(tup1)
print(len(tup1))
tup2=tup1+tuple(range(6,11))
print(tup2)
print(len(tup2))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值