20.12. Write Code Questions¶
-
Create a subclass of the
Parentclass namedChildthat overrides the inheritedeye_color()method to return"I have green eyes." -
Create a subclass of the
Greeterclass namedGrumpyGreeterthat overrides the inheritedgreetmethod to return"Go Away!". -
Create a subclass of the
Animalclass namedCowthat overrides the inheritednoisemethod to return"Moo". -
Create a subclass of the
Actorclass namedOverActorthat overrides the inheritedactmethod to return"I am super happy!". -
Create a subclass of the
Studentclass namedGradStudentthat calls the__init__method inStudentto initialize the first and last name and overrides the inheritedfav_foodmethod to return"Sushi". -
Write a function
is_ascending(nums)that returnsTrueif the numbers in the listnumsare sorted in ascending order andFalseotherwise. If the listnumshas 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,l1andl2and returns a list with the sum of the corresponding items inl1andl2. 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 returns0ifvalueis <= 0.25,1ifvalueis > 0.25 and <= 0.5,2ifvalueis > 0.5 and <= 0.75, and3ifvalue> 0.75. -
Fix the function
dup_adjacent(nums)to returnTrueif there are duplicate adjacent values innums. For example,dup_adjacent([1,2,1])should returnFalseanddup_adjacent([4, 3, 3, 2])should returnTruebecause of the adjacent 3’s. ReturnFalseif the length of the list is less than two.