我想修改这个代码,因为当用户给出正确的名称,但错误的密码代码必须从输入密码运行,而不是从再次输入用户名运行


while True:
print("who is this?")
name=input()
if name!='shubh':
continue
print("hi its you shubh. type your password")  
password=input()
if password!="shubh": 
print("try again. wrong password")
elif password=="shubh":
break
print("access granted")

当用户给出正确的id但密码错误时,必须从密码输入开始运行代码,而不是从启动开始运行

您可以按照@ewong建议的进行尝试

while True:
print("who is this?")
name=input()
if name=='shubh':
break
print("Please try again")
while True:
print("hi its you shubh. type your password")
password=input()
if password!="shubh":
print("try again. wrong password")
elif password=="shubh":
break
print("access granted")

最新更新