Created
March 23, 2021 23:11
-
-
Save AnisahTiaraPratiwi/84c1b400b2f641956429067c74b8a1ea to your computer and use it in GitHub Desktop.
Use a list comprehension to create a list of squared numbers (n*n). The function receives the variables start and end, and returns a list of squares of consecutive numbers between start and end inclusively. For example, squares(2, 3) should return [4, 9].
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def squares(start, end): | |
return [x*x for x in range(start, end+1)] | |
print(squares(2, 3)) # Should be [4, 9] | |
print(squares(1, 5)) # Should be [1, 4, 9, 16, 25] | |
print(squares(0, 10)) # Should be [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment