gpt4 book ai didi

What should i add to the code to make run the while statement for password? [duplicate](我应该在代码中添加什么,以使密码运行While语句?[复制])

转载 作者:bug小助手 更新时间:2023-10-26 19:40:58 25 4
gpt4 key购买 nike




password = "joseph123"
x = str(input("Please enter your password: "))
if x == password:
print("Hurray!!! your password is correct ")
elif x != password:
print("Please try your password again ")

It only gives me the question to insert password once if the password is wrong and doesn't repeat to continue until the user gets it correctly
and also after putting the wrong password and then putting the right password it till shows wrong password

如果密码错误,它只会提示我插入一次密码,并且不会重复输入密码,直到用户获得正确的密码,然后输入错误的密码,然后输入正确的密码,直到显示错误的密码


更多回答

docs.python.org/3/tutorial/…

docs.python.org/3/tutorial/...

@Mark how is it not? That's the point where loops, which are what the OP refers to in the title and needs if it "doesn't repeat to continue", are introduced.

@马克,怎么会不是呢?这就是引入循环的地方,循环是OP在标题中所指的,如果它“不重复继续”,就需要循环。

take a look at this OP, if you're not familiar! :-) docs.python.org/3/reference/compound_stmts.html#while

如果你不熟悉,请看一下这个操作!:-)docs.python.org/3/reference/compound_stmts.html#while

Your question title suggests that you've heard of while loops. Did you consider trying to write one?

你的问题标题表明你听说过while循环。你有没有想过写一本?

If you want to have a while statement, why don’t you add a while statement?

如果您想要一条While语句,为什么不添加一条While语句呢?

优秀答案推荐

Use the while statement to continuously loop over the entries. That'd be:

使用WHILE语句连续循环遍历条目。那就是:


password = "joseph123"
x = str(input("Please enter your password: "))

while x != password:
# show error
print('Please try your password again')
x = str(input('Try again: '))

print('Hurray!!! your password is correct')


You might want to try a loop here, as the code is now it is going to stop after one pass through since there is only one iteration of the if statement. If you used something like while x!= password it might work better.

您可能想在这里尝试一个循环,因为代码现在是,它将在一次传递后停止,因为if语句只有一次迭代。如果您使用的是While x!=Password这样的内容,它可能会工作得更好。


更多回答

what is the use/need of the else:

Else的用途/需求是什么:

no need for it. oops

不需要了,哎呀

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com