I am writing a python program in which I want to allow the user to enter only 10 numbers from the terminal. If they try to enter more than 10 it should prompt that they can't enter more than 10 numbers. How can I achieve this in python?
My code looks like as follows:
def get_list():
'''takes data from the user to create a list'''
error =True
while error == True:
error =False
user_data = raw_input("Please enter integers separated by space:" )
listofdata =user_data.split()
for item in listofdata:
try:
item = int(item)
except:
print("Please enter only numbers separated by spaces")
error =True
break
return listofdata