I'm new to programming, and I'm looking for some advice on what to do. The program I'm trying to write will need several numbers from the user. I want to use a function to test if the user input a number or not for each of the values entered. If the input isn't a number, I want the function to keep asking for a number until one is entered. I want to know if there is a better way to pass the value into a global variable other than explicitly declaring each variable in the function as global. I'm unsure if there is a better way to do this...
rowNum = None
def numTest(c, d):
x = False
while x is not True:
try:
c = raw_input(d)
c = float(c)
x = True
except:
print "The value you entered isn't a valid number, please try again."
global rowNum
rowNum = c
numTest(rowNum, "Enter number of rows: ")
print rowNum
# I want to use the numTest function on several variables...
# e.g.
# numTest(contourLevel, "Enter number of contour levels: ")
# numTest(cellSize, "Enter cell size: ")
# numTest(labelSize, "Enter label size: ")