In: Computer Science
Write a Python program:
The function is named validity(). It receives 2 floating point parameters, min and max, from the program that invoked it. The function asks the user to enter a float number. Using a while loop it checks whether the number is valid (between min and max, inclusive). If not valid, the while loop uses this statement to prompt for a new number: num = float (input (" Enter a number that is at least :"+ str(min) + "and at most: "+ str(max) + " : ")). Once the function decides a number is valid, it returns it to the program. The program inputs 2 floating point numbers, max and min. It then invokes the validity() function with this statement: “validNum = validity(max,min)”. Once a valid number is returned to the program by the function. The program will print out the values of max, min, and the valid number returned.
def validity(minN,maxN):
while(True):
num = float (input (" Enter a number that is at least :"+ str(minN) + " and at most: "+ str(maxN) + " : "))
if num>=minN and num<=maxN:
return num
minN=1
maxN=100
validNum = validity(minN,maxN)
print("Min = ",minN,"Max = ",maxN,"Valid Num = ",validNum)
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me