Just recently started learning python and ran into a bit of an odd problem. I've created this function to ensure that the number entered by a user is larger than zero:
def numcheck(value,variable):
while value <= 0:
print('The' +str(variable) + 'must be greater than zero! ')
value = float(input('Please enter a positive number for' +str(variable)+ \
'and press enter. '))
return value
The function is used within a main function as follows:
def main():
length = float(input('What is the length of the block of cheese? '))
numcheck(length,' length of the block ' )
My problem is that the function successfully recognizes non-positive values, but when a new value is entered, the original number is still passed to the rest of the function. For example, if -10 is entered into length, I will be prompted to enter another value. If 15 is entered, the while loop will close but -10 will still pass from the function completely ruining the arithmetic that follows. I have spent several hours trying to remedy this with no success. I would appreciate any advice y'all have to offer. Thanks so much!