20.12. Write Code Questions¶
-
Create a subclass of the
Parent
class namedChild
that overrides the inheritedeye_color()
method to return"I have green eyes."
-
Create a subclass of the
Greeter
class namedGrumpyGreeter
that overrides the inheritedgreet
method to return"Go Away!"
. -
Create a subclass of the
Animal
class namedCow
that overrides the inheritednoise
method to return"Moo"
. -
Create a subclass of the
Actor
class namedOverActor
that overrides the inheritedact
method to return"I am super happy!"
. -
Create a subclass of the
Student
class namedGradStudent
that calls the__init__
method inStudent
to initialize the first and last name and overrides the inheritedfav_food
method to return"Sushi"
. -
Write a function
is_ascending(nums)
that returnsTrue
if the numbers in the listnums
are sorted in ascending order andFalse
otherwise. If the listnums
has less than two numbers in it returnTrue
. For example,is_ascending([1,2,3])
should returnTrue
,is_ascending([1])
should also returnTrue
, andis_ascending([3,2,1])
should returnFalse
. -
Write a function
sum_lists(l1,l2)
that take two lists of numbers,l1
andl2
and returns a list with the sum of the corresponding items inl1
andl2
. For example,sum_lists([1,2],[3,4])
would return [4,6]. If the two lists are of different length then returned list should be the same length as the shortest list. For example,sum_lists([1],[4,3])
should return[5]
. -
Write a function
avg_pos(nums)
that returns the average of the positive numbers in the listnums
. For example,avg_pos([80, -20, 90])
should return85.0
. -
Write a function
quartile(value)
that returns0
ifvalue
is <= 0.25,1
ifvalue
is > 0.25 and <= 0.5,2
ifvalue
is > 0.5 and <= 0.75, and3
ifvalue
> 0.75. -
Fix the function
dup_adjacent(nums)
to returnTrue
if there are duplicate adjacent values innums
. For example,dup_adjacent([1,2,1])
should returnFalse
anddup_adjacent([4, 3, 3, 2])
should returnTrue
because of the adjacent 3’s. ReturnFalse
if the length of the list is less than two.