1

I have a while loop like so:

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.'

and later I want to use the values for h and phase but my IDE is telling me it cannot be defined. The values are being used in a calculation and the phase is printed.

Joe Smart
  • 751
  • 3
  • 10
  • 28

1 Answers1

1

Define your variables outside the while block so they can be used outside such block:

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.'
Paco Abato
  • 3,920
  • 4
  • 31
  • 54