Powers¶
Save both functions into the file powers.py.
Write the function
powers_1()that takes two positive integers,xandmaxn, and returns the average of the sequence of powers ofxless than or equal tomaxn. Examples:>>> round(powers_1 (2, 100), 2) 18.14 >>> round(powers_1 (3, 200), 2) 24.2 >>> round(powers_1 (5, 100), 2) 10.33 >>> round(powers_1 (7, 1000), 2) 100.0
Note
More tests are provided in file
powers-1.txtWrite the function
powers_2()that takes two positive integers,xandmaxn, and another integer,d, such that0<=d<10, and returns the first number of the sequence of powers ofxless than or equal tomaxnsuch that its digit in the units position isd. If there is no such number, this function must return-1. Examples:>>> powers_2 (2, 100, 6) 16 >>> powers_2 (2, 100, 5) -1 >>> powers_2 (5, 100, 5) 5 >>> powers_2 (5, 100, 3) -1 >>> powers_2 (7, 1000, 3) 343
Note
More tests are provided in file
powers-2.txt
Solution
A solution is provided in file powers.py