182k views
5 votes
Write a function that takes as input two parameters: The first parameter is a positive integer representing a base that is guaranteed to be greater than 1. The second parameter is an integer representing a limit. The function should return a list containing all of the non-negative powers of the base less than the limit (not including the limit). The powers should start at base^0=1 and increase from there until the limit. If the limit is less than 1 the functions should just return an empty list

User Harriyott
by
6.1k points

1 Answer

0 votes

Answer:

Written in Python:

def powerss(base, limit):

outputlist = []

i = 1

output = base ** i

while limit >= output:

outputlist.append(output)

i = i + 1

output = base ** i

return(outputlist)

Step-by-step explanation:

This declares the function

def powerss(base, limit):

This creates an empty list for the output list

outputlist = []

This initializes a counter variable i to 1

i = 0

This calculates base^0

output = base ** i

The following iteration checks if limit has not be reached

while limit >= output:

This appends items to the list

outputlist.append(output)

The counter i is increased here

i = i + 1

This calculates elements of the list

output = base ** i

This returns the output list

return(outputlist)

User Johannes Wachs
by
4.6k points