Question: Write a program which first defines a function evens(n). The function should take an integer as the argument and return a list of n even integers starting with 2 using the range function which takes a third argument that is the “step”. Rewrite the function using the third argument in the range.
What I have so far:
def evens(n):
evensLst = []
for i in range(1,n+1):
evensLst.append(2*i)
return evensLst
for i in range(1,n+1):
evensLst.append(3*i)
return evensLst
n = raw_input("Enter an integer: ")
print "Evens: ", evens(n)
If you use the “third” argument of range, you get the list you are looking for directly.