簡體   English   中英

打印間隔模式在python中輸出的星形模式

[英]print star pattern with interval range output in python

到目前為止,我已經可以打印星形圖案了

lower = int(input("what is the minimum nmber of stars: "))
upper = int(input("what is the maximum number of stars: "))
interval=int(input("enter the interval:"))

for i in range (lower,upper+1,interval):
    print((lower) * ' ' + i * '*')

僅打印出星星,例如:

***

我正在尋找的是

***(3 stars)

********(7 stars)

***********(11 stars)

如何打印文字部分(x個星標)?

用這個:

lower = int(input("what is the minimum nmber of stars: "))
upper = int(input("what is the maximum number of stars: "))
interval=int(input("enter the interval:"))

for i in range (lower,upper+1,interval):
    print(lower*' ' + i*'*', '({} stars)'.format(i))

輸出:

what is the minimum nmber of stars: 1
what is the maximum number of stars: 4
enter the interval:1
 * (1 stars)
 ** (2 stars)
 *** (3 stars)
 **** (4 stars)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM