I am trying to create a list with user input that has at least eight items in the list. I can make the list and put in the user input, but I need to validate that there are indeed eight items, and ask for more if there are not. Then I need the list to print.
I have tried using a while statement for len(list)<8, and an if/else statement for the same. Both are asking for the additional input, but neither are printing the list at the end. I tried a nested loop with while len(list)<8 and inside is an if/else loop, but that returned the same errors as the original while statement.
>>>def main():
... userinput= input("Enter a list of at least eight words separated by a comma: ")
... list= userinput.split(",")
... while len(list)<7:
... print("Please enter more words")
... more_input= input()
... more_input.split(",")
... list.append(more_input)
... print(list)
OR
>>> def main():
... userinput= input("Enter a list of at least eight words separated by a comma: ")
... list= userinput.split(",")
... if len(list)<7:
... print("Please enter more words")
... more_input= input()
... more_input.split(",")
... list.append(more_input)
... else:
... print(list)
Errors with while loop: It just keeps asking for more input even when the list has the minimum required input
>>> main()
Enter a list of at least eight words separated by a comma: This, is, a, list
Please enter more words
More, words
Please enter more words
Three, more, words
Please enter more words
Errors with if/else loop: It only checks once. If the length is good, it prints the list. If the length is not good, it asks for more input and then stops. It neither checks the length again nor prints the list.