0

I need help in making a validation function to help me get an error output when the user input is repeated.

this is just a part of the code that i am doing and i just need help in making a validation function.

Color_ID_List=[]
maxColorList=15
while len(Color_ID_List)<maxColorList:
    b=input("Enter New color: ")
    c=int(input("Enter ID: "))
    d=input("Enter type of color: ")
    print("The ID of", b, "is", c,"and the type of color is",d)
    Color_ID_List.append(b)
    Color_ID_List.append(c)
    Color_ID_List.append(d)

print("")
print("")
print("The following colors and ID has been added")
print(Color_ID_List)
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
Dean
  • 133
  • 8
  • make a `set()` of ids and compare against it - disallow same inputs... – Patrick Artner Jan 20 '19 at 15:48
  • Possible duplicate of [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – Patrick Artner Jan 20 '19 at 15:49

1 Answers1

0

Try using the in statement. This would look something like this:

def validationFunction(input, list):
  if input in list:
    return False
  else:
    return True

When this function returns True, the input is already in the list.