0

Im still very new when it comes to python so be easy on me. Whenever I test this code it comes back with "None" instead of the input entered. Any idea why it could be happening?

def inputLandValue():
    while(1):
        try:
            value=int(input('Please enter the value of the property '))
            break
        except:
            print('Please enter a whole number (10000)')
            return value
def main():
    while(1):
        landValue = inputLandValue()
        print(landValue)
        doMoreStuff = input('Do you want to continue? y/n ')
        if(doMoreStuff.lower() != 'y'):
            break
main()
input() 
0

2 Answers 2

5

You indented your return value line too far. It is part of the except: handler, so it is only executed when you have no value! It should be outside the while loop:

def inputLandValue():
    while(1):
        try:
            value=int(input('Please enter the value of the property '))
            break
        except:
            print('Please enter a whole number (10000)')
    return value

or replace the break with return value:

def inputLandValue():
    while(1):
        try:
            value=int(input('Please enter the value of the property '))
            return value
        except:
            print('Please enter a whole number (10000)')

You should really only catch ValueError however; this isn't Pokemon, don't try to catch'm all:

except ValueError:
Sign up to request clarification or add additional context in comments.

1 Comment

I would like to give an other +1 for the pokemon reference !
0

You can fix your problem by just putting 'return value' in place of the break in main().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.