I am trying to find a neater way to do the following input check:
def intInputCheck():
while True:
try:
INPUT = int(input("INPUT -> "))
return INPUT
except ValueError:
print("Please only input integers")
def createGroup():
possibleSupervisors = ["USER1","USER2"] #etc
print("Possible supervisors:\n{}".format(possibleSupervisors))
for i in range(0, len(possibleSupervisors)):
print(i, ":", possibleSupervisors[i][0])
"""
supervisor = intInputCheck
while supervisor() not in range(0, len(possibleSupervisors)):
print("Please only input numbers in the range provided")
"""
#The above kinda works, but i cant then use the variable "supervisor"
"""
supervisor = intInputCheck()
while supervisor not in range(0, len(possibleSupervisors)):
supervisor = intInputCheck()
print("Please only enter integers in the given range")
"""
"""
The above works, however I end up giving out two print statements if
the user doesnt input an integer which I don't want, I want it to
only output the print statement if that specific error occurs, in
this, If a str is entered, the func will output "only enter ints" and
then the while will output "only ints in given range" which is a pain
"""
I am also trying to see if closures could be useful in simplifying this code, the reason I want to do this is to make my code neater (I think having the same input before and then inside a while loops looks bad). The reason for the function is so that I can use this input checking function in various parts of my program