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")