Syntax Error

This is the place for queries that don't fit in any of the other categories.

Syntax Error

Postby TempDecal » Wed Mar 27, 2013 2:03 am

Code: Select all
aCount = 0
cCount = 0
tCount = 0
gCount = 0

dna = float( input( "Type a float: " )

             
for c in dna
    if c == 'a'
        aCount = aCount + 1
    elif c == 'c':
        cCount = cCount + 1
    elif c == 't':
        tCount = tCount + 1
    elif c == 'g':
        gCount = gCount + 1

dnalength = len(dna)

print ("Pecentage of A's in sequence:") , (float(aCount) / dnalength) * 100



I am constantly getting errors and can't figure out a way around them.
I am using the latest version of python.
Please help :)
TempDecal
 
Posts: 4
Joined: Wed Mar 27, 2013 2:01 am

Re: Syntax Error

Postby metulburr » Wed Mar 27, 2013 2:12 am

I am using the latest version of python.

That does not mean anything. For example, linux could be using a different default version, who knows. We need a number

The first error i get is:
Code: Select all
for c in dna
    if c == 'a'

you forgot 2 semi-colons for the for loop and the first if condition.

The second on is:
Code: Select all
dna = float( input( "Type a float: " )

You are missing a parenthesis

Then after that. You are trying to loop a float?
New Users, Read This
version Python 3.3.2 and 2.7.5, tkinter 8.5, pyqt 4.8.4, pygame 1.9.2 pre
OS Ubuntu 13.04, Mint 11, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
User avatar
metulburr
 
Posts: 1088
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Syntax Error

Postby TempDecal » Wed Mar 27, 2013 2:18 am

python 3.3.0 for windows


Code: Select all
for c in dna:
    if c == 'a':


It still gives me an error for the ":" in "for c in dna:"


I thank you for your assistance!
TempDecal
 
Posts: 4
Joined: Wed Mar 27, 2013 2:01 am

Re: Syntax Error

Postby metulburr » Wed Mar 27, 2013 2:20 am

It still gives me an error for the ":" in "for c in dna:"

Place traceback error next time also.

what do you mean like this?
Code: Select all
  File "forum3.py", line 9
    for c in dna:
                ^
SyntaxError: invalid syntax


If this is the error you are getting , this means you still havent added the missing parenthesis on
Code: Select all
dna = float( input( "Type a float: " )

LOOK there are only 3 parenthesis!!

After that. You are going to get this error though:
Code: Select all
TypeError: 'float' object is not iterable

because you are trying to loop a float. I am not sure why?
New Users, Read This
version Python 3.3.2 and 2.7.5, tkinter 8.5, pyqt 4.8.4, pygame 1.9.2 pre
OS Ubuntu 13.04, Mint 11, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
User avatar
metulburr
 
Posts: 1088
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Syntax Error

Postby TempDecal » Wed Mar 27, 2013 2:33 am

I think I misunderstood the use of float. I switched it to just input() and it seems to have corrected my error along with the ones you mentioned earlier.

Thank you very much for the help :)
TempDecal
 
Posts: 4
Joined: Wed Mar 27, 2013 2:01 am

Re: Syntax Error

Postby metulburr » Wed Mar 27, 2013 2:40 am

input() gets the input and returns a string. If that is wrapped in float() then the string gets converted to a float.
New Users, Read This
version Python 3.3.2 and 2.7.5, tkinter 8.5, pyqt 4.8.4, pygame 1.9.2 pre
OS Ubuntu 13.04, Mint 11, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
User avatar
metulburr
 
Posts: 1088
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Syntax Error

Postby TempDecal » Wed Mar 27, 2013 3:58 am

Here is my final code.

Code: Select all
aCount = 0
cCount = 0
tCount = 0
gCount = 0

dna = input( "Type a float: " )

             
for c in dna:
    if c == 'a':
        aCount = aCount + 1
    elif c == 'A':
        aCount = aCount + 1
    elif c == 'c':
        cCount = cCount + 1
    elif c == 'C':
        cCount = cCount + 1
    elif c == 't':
        tCount = tCount + 1
    elif c == 'T':
        tCount = tCount + 1
    elif c == 'g':
        gCount = gCount + 1
    elif c == 'G':
        gCount = gCount +1

dnalength = len(dna)


def find_all(string,char):
     return [i for i in range(len(string)) if string.startswith(char, i)]

string=dna
charPositionToFind=['b', 'B','d','D','e','E','f', 'F', 'h', 'H', 'i', 'I', 'j', 'J', 'k','K', 'l', 'L','m','M','n','N','o','O','p','P','q','Q','r','R','s','S','u','U','v','V','w','W','x','X','y','Y','z','Z']
position=[]

for char in charPositionToFind:
    s = find_all(string,char)
    position.extend(s)

print ("The number of a's ", aCount)
print ("The number of c's ", cCount)
print ("The number of t's ", tCount)
print ("The number of g's ", gCount)
print ("Precentage of GC content is: ", (gCount + cCount) / dnalength * 100)
print (sorted(position))


this is the outcome for: AAGGCCCTTaaGtTGGGXGGGAAyT
Code: Select all
The number of a's  6
The number of c's  3
The number of t's  5
The number of g's  9
Precentage of GC content is:  48.0
There were invalid characters(s) at position(s): [17, 23]


The invalid character positions are off by 1 it should be [18,24]
is there any insight to why I am losing 1 on each number?
TempDecal
 
Posts: 4
Joined: Wed Mar 27, 2013 2:01 am


Return to General Coding Help

Who is online

Users browsing this forum: micseydel, snippsat and 2 guests