新用户可以使用已经存在的用户名(文本文件问题)创建一个帐户
我是Python的新手,并且正在尝试创建可靠的帐户创建和存储程序。当用户想创建一个新的用户名时,读取用户名_Storage文件以查看它是否已经存在于另一个帐户。
# Enter and check username
new_user = input("Username: ")
if new_user in username_storage:
print("Sorry, that username is already taken.\n")
else:
break
问题是,每当用户尝试使用现有用户名的一部分创建新帐户时,该程序就不允许它,因为它会注册新用户名在预制用户名中。
例如,如果“ William”是USERNAME_STOREAGE文本文件中的现有用户名,则不允许新的用户名“ Will”或“ Liam”,因为这些名称在“ William”中。
感谢任何能够回答这个问题的人;如果我还没有足够清楚地解释我的问题,请告诉我!
I'm relatively new to python and am trying to create a reliable account creation and storage program. When the user wants to create a new username, the username_storage file is read to see if it already exists for another account.
# Enter and check username
new_user = input("Username: ")
if new_user in username_storage:
print("Sorry, that username is already taken.\n")
else:
break
The problem is that whenever the user tries to create a new account using part of an existing username, the program does not allow it because it registers that the new username is inside a pre-made username.
e.g. if "william" is an existing username in the username_storage text file, it doesn't allow the new username "will" or "liam" because those names are inside "william".
Thanks to anyone who may be able to answer this question; if I haven't explained my problem clearly enough, please let me know!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您在用户名中没有空间,会做您想做的事
would do what you want assuming you cant have spaces in the username