This is my 6th day of 100daysofcoding. I continue to learn from Coursera Python Data Structure course and also did some assignments. I tired to write code to find even and odd numbers from list. My code is right below.
My Solution
- Create a empty dictionary
- Give list of numbers
- Loop through each numbers and find out even numbers and keep it in even list similarly find odd numbers and keep it in odd list.
my_dict = {}
numbers = list(range(1,11))
even = []
odd = []
for n in numbers:
if n % 2 == 0:
even.append(n)
else:
odd.append(n)
my_dict["odd"] = odd
my_dict["even"] = even
print(my_dict)
#100DaysOfCode , day 6 #Python
— Durga Pokharel (@mathdurga) December 29, 2020
* More about python Dictionary
* More about Loop
* Python program to find out even and odd numbers from list. pic.twitter.com/YTrsgbmSy7
Top comments (4)
Code looks fun. I am sure you have come across the concept of functions, modules and how to use
return
. Try using functions and add a unit test for the function. You can have a separate file for testing or keep the code (function) in the same file as the test.This is great idea. Will try it. Thanks
Nice. Keep it up. May be you can try implementing more advance data structures in coming days. 😀
Yes. Thank you for the support.