Issue
I need to design a function named firstN that, given a positive integer n, displays on the screen the first n integers on the same line, separated by white space.
An example of using the function could be:
>>> firstN(10)
0 1 2 3 4 5 6 7 8 9
I have done this:
def firstN(n):
for i in range(10):
print (i, end=" ")
firstN(10);
but I can't put end=" " because my teacher has a compiler that doesn't allow it
Solution
You can use starred expression to unpack iterable arguments:
def firstN(n):
print(*(range(n)))
firstN(10)
# 0 1 2 3 4 5 6 7 8 9
Answered By - Arifa Chan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.