gpt4 book ai didi

python - 循环直到特定的用户输入

转载 作者:太空狗 更新时间:2023-10-29 20:44:15 24 4
gpt4 key购买 nike

<分区>

我正在尝试编写一个猜数程序,如下所示:

def oracle():
n = ' '
print 'Start number = 50'
guess = 50 #Sets 50 as a starting number
n = raw_input("\n\nTrue, False or Correct?: ")
while True:
if n == 'True':
guess = guess + int(guess/5)
print
print 'What about',guess, '?'
break
elif n == 'False':
guess = guess - int(guess/5)
print
print 'What about',guess, '?'
break
elif n == 'Correct':
print 'Success!, your number is approximately equal to:', guess

oracle()

我现在要做的是让这个 if/elif/else 命令序列循环直到用户输入“正确”,即当程序规定的数字大约等于用户数时,但是如果我不知道用户数我想不出如何实现和 if 语句,我尝试使用 'while' 也不起作用。

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