Problem: Print first n even numbers.
Example:
2 4 6 8 10 12 ...
Solution in Python:
def even_numbers(n):
"""
Author: Mayur P Srivastava
"""
numbers = []
for i in range(n):
numbers.append(2 * (i+1))
print " ".join([str(e) for e in numbers])
Concepts learned: Single loop.
No comments:
Post a Comment