Remove (,) in for loop(python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
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