howto print list without brackets and comma python
Question:
ISBN = [int(e) for e in input("input ISBN :")]
sum = 10*ISBN[0]+9*ISBN[1]+8*ISBN[2]+7*ISBN[3]+6*ISBN[4]+5*ISBN[5]+4*ISBN[6]+3*ISBN[7]+2*ISBN[8]
for i in range(0,10):
sum_check = sum + i
if sum_check % 11 ==0:
print("n10 =",i)
ISBN.append(i)
OUTPUT
n10 = 5
[0, 2, 0, 1, 3, 1, 4, 5, 2, 5]
but i want this output
020134525
Answers:
If you want to print the list AS IS, python will alway print it within brackets:
[0, 2, 0, 1, 3, 1, 4, 5, 2, 5]
If you want to get all the numbers together, it means you want to join
the numbers in the list.
What you want to do is join
the items in the list, like this:
result = ''.join(list)
The object result
will be the numbers as you wanted, as:
020134525
Try ''.join(ISBN)
Alternatively, instead of having ISBN
as a list, make it str
.
ISBN = ''
(your code)
ISBN+=i
To print any list in python without spaces, commas and brackets simply do
print(*list_name,sep='')
if ISBN = [0, 2, 0, 1, 3, 1, 4, 5, 2, 5]
Then you can write
ISBN = [0, 2, 0, 1, 3, 1, 4, 5, 2, 5]
print(''.join(str(i) for i in ISBN))
ISBN = [int(e) for e in input("input ISBN :")]
sum = 10*ISBN[0]+9*ISBN[1]+8*ISBN[2]+7*ISBN[3]+6*ISBN[4]+5*ISBN[5]+4*ISBN[6]+3*ISBN[7]+2*ISBN[8]
for i in range(0,10):
sum_check = sum + i
if sum_check % 11 ==0:
print("n10 =",i)
ISBN.append(i)
OUTPUT
n10 = 5
[0, 2, 0, 1, 3, 1, 4, 5, 2, 5]
but i want this output
020134525
If you want to print the list AS IS, python will alway print it within brackets:
[0, 2, 0, 1, 3, 1, 4, 5, 2, 5]
If you want to get all the numbers together, it means you want to join
the numbers in the list.
What you want to do is join
the items in the list, like this:
result = ''.join(list)
The object result
will be the numbers as you wanted, as:
020134525
Try ''.join(ISBN)
Alternatively, instead of having ISBN
as a list, make it str
.
ISBN = ''
(your code)
ISBN+=i
To print any list in python without spaces, commas and brackets simply do
print(*list_name,sep='')
if ISBN = [0, 2, 0, 1, 3, 1, 4, 5, 2, 5]
Then you can write
ISBN = [0, 2, 0, 1, 3, 1, 4, 5, 2, 5]
print(''.join(str(i) for i in ISBN))