Question: How can I consolidate this Python code to be DRY and not repetitive. def create_odds(num): Creates a list of len(num) of random odd numbers between

How can I consolidate this Python code to be DRY and not repetitive.

def create_odds(num): Creates a list of len(num) of random odd numbers between 1 and 1000 num_list = [] for i in range(0, num): new_num = 2 while new_num % 2 == 0: new_num = random.randint(1, 1000) num_list.append(new_num) return num_list def create_evens(num): Creates a list of len(num) of random even numbers between 1 and 1000 num_list = [] for i in range(0, num): new_num = 1 while new_num % 2 != 0: new_num = random.randint(1, 1000) num_list.append(new_num) return num_list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!