我目前正在編寫一個基本的骰子軟件密碼生成器。打印最終密碼組合時遇到問題。我正在打印的字符串是將每個單詞打印在新的一行上,而不是一行上的整個字符串。我不太清楚爲什麼。Python中的打印功能是在新行上打印結果
我的代碼如下:
import random
finalPass=""
def choosePass():
global finalPass
i=0
j=0
while(i<=5):
num=""
num=str(random.randint(1,6))
while(j<4):
num=num+str(random.randint(1,6))
j+=1
f=open('container', 'r')
for line in f:
if(line[0:5]==num):
line=line[6::]
line=line.replace(' ','')
#Add the new word to the string of old words
finalPass+=str(line,)
f.close()
j=0
i+=1
#This is printing each word to a new line. I want it to print to the same line
print(finalPass)
choosePass()
請解決您的帖子 –
感謝你修復它 –
對不起新:)添加代碼窗口 – Kiro