I wrote this script from a Youtube video tutorial to practice coding in python for bioinformatics. When I try to run the .py file in Python 3.7
, I get this error print "number of g's " + str(g)
.
The .py file and .txt file it reads is in the same folder on my desktop. I'm using Windows.
# First python program.
# GC content
gene = open("OCA2.txt", "r")
# set values to 0
g=0;
a=0;
c=0;
t=0;
# skip the first header line
gene.readline()
for line in gene:
line = line.lower()
for char in line:
if char == "g":
g+=1
if char == "a":
a+=1
if char == "c":
c+=1
if char == "t":
t+=1
print "number of g's " + str(g)
print "number of c's " + str(c)
print "number of a's " + str(a)
print "number of t's " + str(t)
# 0. = convert to floating point
gc = (g+c+0.) / (a+t+c+g+0.)
print "gc content: " + str(gc)