2013-09-22 18 views
1

乘以變量這裏是我的代碼如何添加一個空格,當你在python

print("Type in another set of words") 
    x = input() 
    print("Now type in how many times you want it to appear (WHOLE NUMBERS ONLY!)") 
    c = int(input()) 
    print(x * c) 

我想每一個字乘以時間之間添加一個空格。那可能嗎?

回答

2

使用str.join放置串序列之間的空間:

print(' '.join([x] * c)) 
2

您可以使用字符串格式化:

print('{} '.format(x)*c) 
相關問題