Remove (,) in for loop(python) | Sololearn: Learn to code for FREE!

+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?

1/28/2019 5:50:33 PM

Mohamed Aashik

3 Answers

New Answer

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