我正在尝试在python中制作一个简单的游戏,(我很新,不要太讨厌我了!)当我在空闲编辑器中运行时,我收到了这个错误:
Do you have an account? Y or N: n
What is your username: password
Traceback (most recent call last):
File "C:\Users\Bright Bridge\Desktop\Personal\Python Projects\main.py", line 33, in <module>
check_user_name()
File "C:\Users\Bright Bridge\Desktop\Personal\Python Projects\main.py", line 17, in check_user_name
if set_user_name() in read_file().format():
TypeError: 'str' object is not callable
这是我的代码:
def create_file():
security = open("user.txt", "r+") #I know it's called security, but it's
security.write(set_user_name()) #not really secure...
security.close()
def check_user_name():
security = open("user.txt", "r")
read_file = security.read()
if set_user_name() in read_file().format():
print("Welcome " + set_user_name())
security.close()
else:
print("Invalid Username")
security.close()
def login(username, password):
pass
def set_user_name():
user_name = input("What is your username: ")
return user_name
account_check = input("Do you have an account? Y or N: ")
if account_check == "y" or "Y" or "yes" or "Yes" or "YES":
check_user_name()
else:
create_file()
我做错了什么?
答案 0 :(得分:4)
read_file
现在是一个包含文件内容的字符串。你正在做的是基本上输入'happy'()
。删除read_file()
中的'()'。