所以基本上我在python上写一个程序,我需要的一个子例程是没有重复的昵称,所以我做的是把所有的昵称添加到一个txt文件中,然后我想读取这个文件,确保昵称和文件中的昵称不一样。代码如下:
sAskNick = input ("What nickname would you like to proceed with?: ")
nicknames = open("nicknames.txt","a+")
aAllNicks = []
with open ("nicknames.txt") as f:
aAllNicks = f.read().splitlines()
for i in range(0,4):
while sAskNick == aAllNicks[i]:
print("Nickname used/inappropriate")
else:
print("Valid nickname")
break
在这个昵称.txt文件中,每行只包含一个昵称列表,文件中有5个昵称
如果要在给定昵称位于该文件中时执行操作:
如果每次输入昵称时都要编辑文本文件,可以使用以下方法进行编辑。 注意: 当然,如果您在每行中使用干净的文本文件保留每个昵称,这种情况也会起作用:
在这个问题上你可以达成很多目标。我相信这两个人中的一个能完成
相关问题 更多 >
编程相关推荐