Home > Mobile >  Why doesn't my seperator parameter work ?
Why doesn't my seperator parameter work ?

Time:10-09

I am trying to print i value in one line. I used end but the code grade didn't accept it so I tried sep but it seems not working.

start=int(input("Give starting value: ")) stop=int(input("Give stopping value: "))

print("\nStarting for loop:")

for i in range(start,stop 1): print(i,sep = " ")

print("\n\nThank you for using the program.")

CodePudding user response:

sep is to separate values in the same call to print. You probably actually want to use the end parameter: print(i, end= " ")

CodePudding user response:

The sep keyword is for separating multiple values. the end keyword argument is meant for using to end the line with something other than the default line break.

to demonstrate

>>>
>>> for i in range(12):
...     print(i, end=' - ')
...
0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 
>>>
>>> print(1,2,3,4,5,6,7,8,9,10,11, sep=" - ")
1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11
>>>

As you can see the sep only works when you have multiple values being printed in the same print statement...

  • Related