これは奇妙な一方のビットであり、それは、値が(2つだけの期待値)をブールすると予想される場合に適している、それらのブール値が0または1のいずれかであり、そしていくつかの他の任意のありません文字列、aaand入力を保存したくない場所。
while int(input()) != 1:
# <logic for else>
pass # only put this if there's no logic for the else.
print("Hi!")
のような代替方法があるけれども:
choose = int(input())
while choose != 1:
<logic for else>
choose = int(input())
それとも機能を作成することができます。これ
def poll_input(string, expect, map_fn=str):
"""
Expect := list/tuple of comparable objects
map_fn := Function to map to input to make checks equal
"""
if isinstance(expect, str):
expect = (expect,)
initial = map_fn(input(string))
while initial not in expect:
initial = map_fn(input(string))
return initial
そして、そのように使用します。
print("You picked %d!" % poll_input("choice ", (1, 2, 3), int))
は、より曖昧な場合
ループを使用する必要があります。 – Li357
探している用語は_control flow statement_です。そして、はい、Pythonにはいくつかあります。 @AndrewLiが既に言ったように、これを達成するためにループを使うことができます。 –
基本的に、最近のプログラミング言語では広く使われていない制御構造、つまりGOTO文を探しています。これは[構造化プログラミング](https://en.wikipedia.org/wiki/Structured_programming)の出現のためです。これにはループを使用する必要があります。 –