我试图编写登录页面,Visual Studio说第5行有IndentationError: expected an indented block
我该怎么做才能修复此功能? 我可以像这样编写登录页面吗
这只是为了我的实践,我是一个新的程序员。
def register_acc(x,y,z):
while True:
x = input("Enter nickname: t")
if x.isalnum == True:
while True:
y = char(input("enter pass: t"))
z = char(input("re enter pass:t"))
if y==z:
Bien=[x,y,z]
print("Successful create acc:")
print("Login name:", Bien[0])
Print("Pass: " , Bien[1])
else:
break
else:
break
register_acc(x,y,z)
错误:
File "d:visual studio idecommon7ideextensionsmicrosoftpythoncorePackagesptvsd_vendoredpydevd_pydev_imps_pydev_execfile.py", line 25, in execfile
exec(compile(contents+"n", file, 'exec'), glob, loc)
File "C:UsersAPCsourcereposPythonApplication3PythonApplication3PythonApplication3.py", line 5
x = input("Enter nickname: t")
^
IndentationError: expected an indented block
Press any key to continue . . .
错误准确地告诉您出了什么问题,您忘记缩进while
块。它们应以与函数def
启动和if
语句完全相同的方式缩进。
所以:
def register_acc(x,y,z):
while True:
x = input("Enter nickname: t")
if x.isalnum == True:
while True:
y = char(input("enter pass: t"))
应该是
def register_acc(x,y,z):
while True:
x = input("Enter nickname: t")
if x.isalnum == True:
while True:
y = char(input("enter pass: t"))
其他一些提示:
-
if x == True:
可以简化为if x:
- 函数名称区分大小写,因此
Print()
与print()
不同
如果你刚刚开始使用Python,那么祝你好运,我希望你和我一样有回报!那里有一些很棒的资源,但对于教授如何阅读错误消息,我喜欢软件木工教程。