gpt4 book ai didi

python - 在输出中添加星号

转载 作者:太空宇宙 更新时间:2023-11-03 15:25:05 25 4
gpt4 key购买 nike

我最近开始学习Python,我有一个倒计时器。它工作正常,但我想在输出中添加一个星号。

输出的重新定义是:

Countdown timer: How many seconds? 4          
4****
3***
2**
1*
Blast off

到目前为止我已经:

import time

countDown = input('Countdown Timer: How many seconds?')

for i in range (int(countDown), 0, -1):
print (i)
time.sleep(1)
print ('BLAST OFF')

最佳答案

只需在打印数字时添加 * 即可。

import time

countDown = input('Countdown Timer: How many seconds?')

for i in range (int(countDown), 0, -1):
print (i,"*"*(i))
time.sleep(1)
print ('BLAST OFF')

print str(i)+"*"*(i) - 数字后不留空格。

关于python - 在输出中添加星号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43228584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com