代碼如下:
#?輸入數值,輸入值為str,所以使用int轉換成整數
number?=?int(input("請輸入數值:"))?#?數值輸入
print_str?=?''
for?i?in?range(number):?#?遍歷
temp_str?=?''?#?臨時字符儲存變量
for?j?in?range(number?-?i):?#?累加”*“
temp_str?+=?"*"
temp_str?+=?"?"?#?添加間隔空格
print_str?+=?temp_str?#?增加到輸出字符中
print(print_str[:-1])?#?刪除最後壹個無用的間隔空格打印