File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ # Write a function called count_magical
2+ # that returns the number of even numbers
3+ # in a given list. In the function,
4+ # if the number of evens is greater than
5+ # half of the length of the list, print "Magical"
6+ # Else, print "Not Magical"
7+
8+ # write code here
Original file line number Diff line number Diff line change 1+ # Write a function called count_magical
2+ # that returns the number of even numbers
3+ # in a given list. In the function,
4+ # if the number of evens is greater than
5+ # half of the length of the list, print "Magical"
6+ # Else, print "Not Magical"
7+
8+ def count_magical (my_list ):
9+ number_of_evens = 0
10+ for n in my_list :
11+ if n % 2 == 0 :
12+ number_of_evens += 1
13+
14+ if number_of_evens > len (my_list ) / 2 :
15+ print ("Magical" )
16+ else :
17+ print ("Not Magical" )
18+
19+ return number_of_evens
You can’t perform that action at this time.
0 commit comments