This is the prompt we were given to find the function needed:
A function that prompts the user for the minimum value and returns it to the calling statement. Function to also deal with range checking to make sure that the minimum value provided is greater than 0
Here's my code below however it doesn't print out the error message when I enter a minimum value higher than the maximum value.
def get_min():
return int(input("What's your minimum value?"))
def min_Check(get_min):
if (get_min >= 0):
return print("ERROR. Minimum should be greater than 0")
else:
return get_min
def get_max():
return int(input("What's your maximun value?"))
def max_Check(get_min):
if (get_max <= get_min):
return print(f"ERROR. Maximum value must be greater {min}")
else:
return max
min_value = get_min()
max_value = get_max()
get_check1 = min_Check(get_min)
get_check2 = max_Check(get_min)
CodePudding user response:
note the difference :
1- you make a wrong condition in min_check function
2- you don't use () when you use the output of the two get function in conditions
def get_min():
return int(input("What's your minimum value?"))
def min_Check(get_min):
if (get_min() <= 0):
return print("ERROR. Minimum should be greater than 0")
else:
return get_min
def get_max():
return int(input("What's your maximun value?"))
def max_Check(get_min):
if (get_max() <= get_min()):
return print(f"ERROR. Maximum value must be greater {min}")
else:
return max
min_Check(get_min)
max_Check(get_min)
CodePudding user response:
There are a couple of things in your code that need fixing:
Both max_Check and min_Check have the
else
statement outside the function, I don't know if this was a copy paste error but you need to fix that.You never pass get_max as an argument for max_Check so it will never do the
if
correctly because it is missing an argument. You should have gotten an error for that.