+ 1
Remove (,) in for loop(python)
This is a file handling in pyhthon X=open(âdata.txtâ,âwâ) for s in range(10): num=input(âenter number: â) X.write(num+â,â) X.close() Output in notepad(.txt) 14,74,75,78,89,97,89,9,9, I want remove last num 9âs coma(,) what the code for do that?
3 RĂ©ponses
0
numbers = []
for s in range(10):
num = int(input())
numbers.append(num)
print(','.join(numbers))
+ 2
You can create a list to store the numbers.
numbers = []
You can add a number into the list using numbers.append(num).
Then you can print the list with print(','.join(numbers)).
You won't have to use a file to store the numbers in this way.
+ 2
can you write a code to that? please