ユーザが誤った入力をした場合、コードに正しい値を入力するように指示するようにユーザにプログラムの入力を要求します。特定の複数のtry/except節へのループを返す
私はこのコードを試しましたが、continue
ステートメントのため、非常に最初からループを実行します。コードをそれぞれのtryブロックに戻したい。助けてください。
def boiler():
while True:
try:
capacity =float(input("Capacity of Boiler:"))
except:
print ("Enter correct value!!")
continue
try:
steam_temp =float(input("Operating Steam Temperature:"))
except:
print ("Enter correct value!!")
continue
try:
steam_pre =float(input("Operating Steam Pressure:"))
except:
print ("Enter correct value!!")
continue
try:
enthalpy =float(input("Enthalpy:"))
except:
print ("Enter correct value!!")
continue
else:
break
boiler()
ではなく、各 'try'声明の周りにしばらく入れて?また、 'break'は最後のtry catchにのみ適用されます。 – Torxed
[入力が特定のタイプになるまでループする]の可能な複製(http://stackoverflow.com/questions/19542883/loop-until-an-input-is-of-a-specific-type) –