创建代码以在每个洞后将用户的输入(下注)加倍

2024-04-29 07:51:48 发布

您现在位置:Python中文网/ 问答频道 /正文

bet = int(input('Enter your bet: ')) ##takes bet from user

for i in range (0,18): ##the range is for the number of holes being
                       ##played 
    bet *=2 ##double the bet amount for each hole
    print("hole", i, "$", bet) ## prints the wager for each hole

这是我从这段代码中得到的输出,但是第一个洞应该从10开始,然后从第二个洞开始加倍

Enter your bet: 10
hole 1 $ 20
hole 2 $ 40
hole 3 $ 80
hole 4 $ 160
hole 5 $ 320
hole 6 $ 640
hole 7 $ 1280
hole 8 $ 2560
hole 9 $ 5120
hole 10 $ 10240
hole 11 $ 20480
hole 12 $ 40960
hole 13 $ 81920
hole 14 $ 163840
hole 15 $ 327680
hole 16 $ 655360
hole 17 $ 1310720

Tags: theinfromforinputyourisrange
2条回答

因此,从较小的数字开始,除以2开始数字

bet = int(input('Enter your bet: ')) / 2 ##takes bet from user

for i in range (0,18): ##the range is for the number of holes being
                       ##played
    bet *=2 ##double the bet amount for each hole
    print("hole", i, "$", bet) ## prints the wager for each hole

输出:

Enter your bet: 10
hole 0 $ 10.0
hole 1 $ 20.0
...
hole 17 $ 1310720.0

只需在倍增之前打印值

bet = int(input('Enter your bet: ')) ##takes bet from user

for i in range (1 ,19): ##the range is for the number of holes being played 
    print("hole", i, "$", bet) ## prints the wager for each hole
    bet *= 2 ##double the bet amount for each hole

相关问题 更多 >