PPA-8
Question
Accept a positive integer \(n\) as input and print the first \(n\) integers on a line separated by a comma.
Hint
Consider the following piece of code:
For an input of \(5\), this ends up printing 1,2,3,4,5,
and the last comma is undesirable. How do we get rid of it? You can use an if-else
block:
- If
x == n
, which is the last number you are printing, then justprint(x)
. - If
x != n
, which is any other number in the sequence, thenprint(x, end = ',')
You have enough information to complete the code.