我目前正在编写一个基本的骰子软件密码生成器。打印最终密码组合时遇到问题。我正在打印的字符串是将每个单词打印在新的一行上,而不是一行上的整个字符串。我不太清楚为什么。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