Page 1 of 1

2. (10 points) a. Define a class Parent and implement one property function: three_power() which takes an integer argume

Posted: Tue Jul 12, 2022 8:09 am
by answerhappygod
2 10 Points A Define A Class Parent And Implement One Property Function Three Power Which Takes An Integer Argume 1
2 10 Points A Define A Class Parent And Implement One Property Function Three Power Which Takes An Integer Argume 1 (40.29 KiB) Viewed 38 times
2. (10 points) a. Define a class Parent and implement one property function: three_power() which takes an integer argument and check whether the argument is integer power of 3 (e.g., 1 is 3°, 3 is 3¹, 9 is 3²2, 27 is 3³, 81 is 3¹). b. Define a second class Child to inherit Parent, and implement the following two property functions for Child: (1) add_three power() which is a recursive function taking a parameter of a list of integers (e.g., a defined in the program). The function will calculate and return the sum of all numbers in the list that are integer power of 3; (2) list_GCD() which takes two list arguments a and b as shown in the program, and use the built-in map function to calculate the greatest common divisor (GCD) of each pair of the elements in the two lists (e.g., GCD of 3 and 2, GCD of 6 and 4, GCD of 9 and 18, GCD of 16 and 68, etc.) Note: you can either define the GCD function by yourself or use the built-in GCD function in math module. import math import random a= [3, 6, 9, 16, 32, 57, 64, 81, 100] b=[2, 4, 18, 68, 48, 80, 120, 876, 1256]