Dec-01-2020, 11:22 PM
(Dec-01-2020, 11:17 PM)deanhystad Wrote: You don't handle empty questions correctly. Be careful about using recursion
question_list = [] def get_questions(): question = input("Enter your question: ") if len(question) == 0: print("No Empty Questions.") get_questions() question_list.append(question) return question for _ in range(3): get_questions() print(question_list)Personally I think a blank question is a great way to indicate you are done entering questions, but if you want to keep asking until a question is answered you should use something like this:
Output:Enter your question: 1 Enter your question: No Empty Questions. Enter your question: 2 Enter your question: No Empty Questions. Enter your question: 3 ['1', '2', '', '3', ''] <-- Two blank questions
def get_questions(): while True: question = input("Enter your question: ") if len(question) == 0: print("No Empty Questions.") else: question_list.append(question) return question
That's a cool solution! it doesn't fit the current build because I want the user to type the answers immidietely rather than stack them and then type the answers for them.
I will definetely use this solution in other stuff though!
thanks for your time!