From 08d19da08f5950fda01ee05d3c90b1901af41bfa Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 18 Jan 2021 17:36:06 +0300 Subject: [PATCH] Update random_fact selection method I suppose, defining a new function (def select_random_fact(fact_arr)) is redundant in this case. And for people who aren't familiar with 'random' module or python in general, it might be much easier to understand this part this way, then via generating random index. Also, 'select_random_fact()' if left as is, might raise 'IndexError: list index out of range' at some point. 'len(fact_list)+1' should be changed to 'len(fact_list)-1' --- responses/10_create-python-file.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/responses/10_create-python-file.md b/responses/10_create-python-file.md index 9313a56..f6f97f4 100644 --- a/responses/10_create-python-file.md +++ b/responses/10_create-python-file.md @@ -56,10 +56,7 @@ If Python is a new programming language to you, like always don't worry. You are # Select a random fact from the fact_list and return it # into a variable named random_fact so we can use it - def select_random_fact(fact_arr): - return fact_arr[random.randint(0, len(fact_list)+1)] - - random_fact = select_random_fact(fact_list) + random_fact = random.choice(fact_list) # Print the individual randomly returned cat-fact print(random_fact)