Remove (,) in for loop(python) | Sololearn: Learn to code for FREE!
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?

28th Jan 2019, 5:50 PM
Mohamed Aashik
Mohamed Aashik - avatar
3 Respostas
0
numbers = [] for s in range(10): num = int(input()) numbers.append(num) print(','.join(numbers))
29th Jan 2019, 5:54 AM
giannismach
giannismach - avatar
+ 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.
28th Jan 2019, 6:04 PM
giannismach
giannismach - avatar
+ 2
can you write a code to that? please
29th Jan 2019, 4:45 AM
Mohamed Aashik
Mohamed Aashik - avatar