我有一个像这样的like循环:
while True:
try:
h = int(raw_input("Please Enter your altitude in metres > "))
if h > 0 and h < 11000:
phase = 'Troposphere'
break
except ValueError:
print 'Your entered value contained letters or punctuation. Please enter a numerical value.'稍后,我想使用h和phase的值,但是我的IDE告诉我不能定义它。正在计算中使用这些值,并打印相位。
发布于 2015-02-28 22:28:23
在while块之外定义变量,以便它们可以在这样的块之外使用:
h = 0
phase = 0
while True:
try:
h = int(raw_input("Please Enter your altitude in metres > "))
if h > 0 and h < 11000:
phase = 'Troposphere'
break
except ValueError:
print 'Your entered value contained letters or punctuation. Please enter a numerical value.'https://stackoverflow.com/questions/28787682
复制相似问题