-1
#Exercise 7: Counting...1...2...3...
#The purpose of this program is to ask a file from the user, open the file 
# and counts the number of comma-separated values in it and report the result to the user

name_file = input("Enter name of file: ")

inf = open(name_file, "r")

count_comma = 0 


line = inf.readline()

for char in line:
    if "," in char:
       count_comma +=1

print (count_comma)
inf.close()

when i run it prints 0. why?

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219

1 Answers1

-1

you're probably better off with

count_comma = len(line.split(","))

but you'd have to run timeit to be sure

Schalton
  • 2,867
  • 2
  • 32
  • 44