Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 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 Respostas
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