I have to write this short program that converts digits/symbols in a string into integers. Basically it takes a string containing none or one operation sign "+" or "-" if __init__ allows it, followed by one or more digits, and can contain blank spaces anywhere. It then returns a triple in this format:
(number of characters in the string including blanks, but not including blanks after the digits, "-1" if...
User Profile
Collapse
-
Converting a string into integers
-
Doesn't the index method return an integer index, if I provide it with a variable or a character, ie, basically find where in the string/list that character first appears?
Could you explain what s1.index(c) would do please? And does s2.index(strand 2[i]) mean return the position of the ith character in strand2, as it appears in s2? Thanks. -
Hi thanks for reply.
Enumerate function basically returns a string or list in the form of ordered pairs right? enumerate('ABC' ) would turn into (0, 'A'), (1, 'B'), (2, 'C')?
Sorry I forgot to mention that I cannot use dictionary (I just started this course), as we haven't covered them yet, so I have no idea how dictionaries work. Is there some way to only do it with loops and enumerate if that's necessary?Leave a comment:
-
"Value Error" in Python
Hello, I'm trying to write this simple program that returns True if two equal-length strings are complimentary DNA pairs (ie, if character 1 in string 1 was 'A', character 1 in string 2 has to be 'T', and vice-versa, otherwise it would return false).
This is what I have so far:
Code:[B]for[/B] (base1, base2) [B]in [/B](strand1, strand2): [B]if[/B] (base1, base2) [B]not in[/B] (('A', 'T'), ('T', 'A'), ('C', 'G'), ('G', 'C')): [B]return Fal[/]
No activity results to display
Show More
Leave a comment: