问题我有一个while循环/布尔/或 [英] Problem I have with a while loop/boolean/or
问题描述
大家好。
我的代码有问题:(
-----------
提示= raw_input(\ nA你被困?是/否:)
提示= hint.lower()
while(提示!=''n'')或(提示!=''y''):
提示= raw_input("请指定有效选择:)
---------------------------------- -----------
所以每次我运行程序,输入我的选择为y或n,我是
告诉''请再次指定一个有效的选择''并且不能退出
循环。
------ -----
提示= raw_input(\ nA你被困?是/否:)
提示= hint.lower( )
while(提示!=''n''):
提示= raw_input("请指定有效选项:")
---------------------------------------- -----
至于我输入n时,我可以离开他在回路的时候。
无论如何我不能指责这一点,所以如果有人可以告诉我什么,我真的很感激我做错了。谢谢。
(我有一个男人觉得这真的很傻我忽略了......)
"是******* @ googlemail.com" <是******* @ googlemail.comwrites:
while(hint!=''n'')或(提示!=''y ''):
hint = raw_input("请指定一个有效的选择:")
----------- ----------------------------------
所以每次我跑程序,并输入我的选择为y或n,我是
告诉''请指定一个有效的选择再次''并且不能退出
循环。
假设你的提示是y。问自己这两个问题:
1.(提示!=''n'')是真的吗?
2.是(提示!=''是'')是真的吗?
现在问问自己你的while循环中的条件是什么。
是******* @ googlemail.com 写道:
大家好。
我的代码有问题:(
-----------
hint = raw_input(\ nA你被困?是/否:)
hint = hint.lower()
>
while(提示!=''n'')或(提示!=''y''):
提示= raw_input("请指定有效选择:" )
------------------------------------- --------
所以每次我运行程序,并输入我的选择为y或n,我是
告诉''请再次指定一个有效的选择''并且不能退出
循环。
-----------
提示= raw_input(你死了吗? y / n:")
hint = hint.lower()
while(提示!=''n''):
hint = raw_input("请指定有效选项:")
------------------- --------------------------
至于我输入n时,我可以离开循环。
无论如何我不能把手指放在这上面,所以如果有人可以告诉我我是什么我会真的很感激'做错了。谢谢。
(我有一个男人觉得这真的很傻我忽略了......)
你的if测试是错误的。
如果提示=''n''
提示!=''n''是假的
提示!=''y''是真的
False或True等于True
我想你想要的东西如下:
提示= raw_input(\ nA你被困?是/否:)
提示= hint.lower()
虽然提示不在[''y'','n'']:
hint = raw_input("请指定有效选项:")
-Larry
3月13日晚上10点43分,Paul Rubin< http://phr...@ NOSPAM.invalidwrote:
" israph ... @ googlemail.com" < israph ... @ googlemail.comwrites:
while(hint!=''n'')或(提示!=''y''):
hint = raw_input("请指定有效选项:")
------- --------------------------------------
所以每次我运行程序,并输入我的选择为y或n,我是
告诉''请指定一个有效的选择''并且可以没有退出
循环。
假设你的提示是''y''。问自己这两个问题:
1.(提示!=''n'')是真的吗?
2.是(提示!=''是'')是真的吗?
现在问问自己你的while循环中的条件是什么。
谢谢。
*将我的头放在白纸下* = /
Hi all.
I have a problem with some code :(
-----------
hint = raw_input("\nAre you stuck? y/n: ")
hint = hint.lower()
while (hint != ''n'') or (hint != ''y''):
hint = raw_input("Please specify a valid choice: ")
---------------------------------------------
so everytime I run the program, and enter my choice as y or n, I''m
told to ''Please Specify a valid Choice Again'' and can''t get out of the
loop.
-----------
hint = raw_input("\nAre you stuck? y/n: ")
hint = hint.lower()
while (hint != ''n''):
hint = raw_input("Please specify a valid choice: ")
---------------------------------------------
As for here when I enter n, I can leave the while loop.
Anyway I can''t put my finger on this, so I''d be real grateful if
someone could tell me what I''ve done wrong. Thanks.
(I have a guy feeling it''s something really silly I''m overlooking...)
"is*******@googlemail.com" <is*******@googlemail.comwrites:while (hint != ''n'') or (hint != ''y''):
hint = raw_input("Please specify a valid choice: ")
---------------------------------------------
so everytime I run the program, and enter my choice as y or n, I''m
told to ''Please Specify a valid Choice Again'' and can''t get out of the
loop.Suppose your hint is ''y''. Ask yourself these two questions:
1. Is (hint != ''n'') true?
2. Is (hint != ''y'') true?
Now ask yourself what the condition in your while loop says.
is*******@googlemail.com wrote:Hi all.
I have a problem with some code :(
-----------
hint = raw_input("\nAre you stuck? y/n: ")
hint = hint.lower()
while (hint != ''n'') or (hint != ''y''):
hint = raw_input("Please specify a valid choice: ")
---------------------------------------------
so everytime I run the program, and enter my choice as y or n, I''m
told to ''Please Specify a valid Choice Again'' and can''t get out of the
loop.
-----------
hint = raw_input("\nAre you stuck? y/n: ")
hint = hint.lower()
while (hint != ''n''):
hint = raw_input("Please specify a valid choice: ")
---------------------------------------------
As for here when I enter n, I can leave the while loop.
Anyway I can''t put my finger on this, so I''d be real grateful if
someone could tell me what I''ve done wrong. Thanks.
(I have a guy feeling it''s something really silly I''m overlooking...)
Your if test is wrong.
If hint=''n''
hint !=''n'' is False
hint !=''y'' is True
False or True equals True
I think you want something like:
hint = raw_input("\nAre you stuck? y/n: ")
hint = hint.lower()
while hint not in [''y'', ''n'']:
hint = raw_input("Please specify a valid choice: ")
-Larry
On Mar 13, 10:43 pm, Paul Rubin <http://phr...@NOSPAM.invalidwrote:"israph...@googlemail.com" <israph...@googlemail.comwrites:while (hint != ''n'') or (hint != ''y''):
hint = raw_input("Please specify a valid choice: ")
---------------------------------------------
so everytime I run the program, and enter my choice as y or n, I''m
told to ''Please Specify a valid Choice Again'' and can''t get out of the
loop.
Suppose your hint is ''y''. Ask yourself these two questions:
1. Is (hint != ''n'') true?
2. Is (hint != ''y'') true?
Now ask yourself what the condition in your while loop says.Thanks.
*puts my head under a white sheet* =/
这篇关于问题我有一个while循环/布尔/或的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!