Issue
My program is printing an extra space after every line. I want to remove the extra space from end of each line.
x, y = map(int, input().split())
count = 0
while count < (y//x):
start = count*x + 1
end = (count + 1) * x + 1
for i in range(start,end,1):
print(i,end=" ")
print("")
count+=1
Input: 3 99
Output:
1 2 3
4 5 6
7 8 9
.....
After end of the each line I am printing an extra space, How can I remove this space?
Solution
How about a simpler approach where we print the numbers as a group and control both separator and end character:
x, y = map(int, input().split())
count = 0
while count < y // x:
start = count * x + 1
end = start + x
print(*range(start, end), sep=" ")
count += 1
Answered By - cdlane Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.