• Boolean Logic Advanced Math Operations Advanced String Operations Review and Quiz Unit Project

Counting instances

The count function returns the number of times a given sequence of characters appears in a string.

DNA as a String

DNA encodes biological information as a chain of nucleotides, just as computers encode digital information with 0's and 1's. The four nucleotides in DNA are adenine, guanine, cytosine, and thymine, abbreviated as A, G, C, and T.

We can represent a strand of DNA as a string.

We can then use the count function to count its nucleotides.

GC Content

Given a dna sequence, print the percentage of the nucleotides that are either guanine (G) or cytosine (C). This metric is called the GC content of a DNA sequence.

Use the len function to get the length of the DNA sequence, and use the count function to count the number of G and C characters in the dna string. Don't forget to cast your output as a string!

AT/GC Ratio

Given a dna sequence, print the ratio between A and T nucleotides (adenine and thymine) and C and G nucleotides (cytosine and guanine). This metric is called the AT/GC ratio of a DNA sequence.

Next
© Tynker, 2020

The in operator

The in operator returns True if a certain string is a substring of another string, and False otherwise.

Hair Genes

Assume if the DNA sequence TAGCGGT is in both parents' DNA, their child will have black hair. If the sequence is only in one of the parents' DNA, the child will have brown hair, and if the sequence is in neither of the parents' DNA, the child will have blonde hair.

Given the DNA sequence of a mother and father, print either black, brown, or blonde based on the expected hair color of their child.

not in operator

The not in operator can be used to determine if a string does not contain another string.

In One String But Not the Other

Given two strings str1 and str2, print the characters that are in str1 that are not in str2.

Previous Next
© Tynker, 2020

String Replacement

The replace function replaces all occurrences of the given substring with the replacement string.

You have a necklace of white and black beads represented as a string of w and b characters. Think about replacing each black bead with a white bead, and each white bead with a black bead followed by a new white bead.

Replacing black with white beads, then white with a black-white bead sequence, does not solve the problem correctly. After the first replacement, all of the new white beads will be converted back into a black bead followed by a white bead.

Instead, you need to use an intermediate letter to store where black beads were.

Counting Replacements

You have a necklace of white and black beads represented as a string. For the given number of replacements, replace each black bead with a white bead, and each white bead with a black and white bead, like in the previous problem. Print out the final necklace.

Hint: Use a loop to repeat the replacement process. Repeatedly perform the string replacement explained above.

Previous Next
© Tynker, 2020

String Formatting

The format function inserts values into a string.

Various templates to the format function can quickly perform string manipulation tasks like adding commas into a number.

Previous Next
© Tynker, 2020

Iterating on Strings

You can use a for loop to iterate on strings. In the case of a string, the iteration variable is a copy of each character in the string.

In Both Strings

Given two strings a and b, use a for loop to count the number of letters in a that also appear in b. For every letter in a, check if the letter is in b with the in operator.

Reversing a String

The program below iterates to each letter of forward and adds it to the beginning of reverse. The resulting string has the characters of the original string in reverse order.

Reversing a Name

Given a name, reverse it and then print it out.

Palindromes

A palindrome is a word that is spelled the same forward as backward, like "level" and "racecar". Given a lowercase word, print palindrome if it is a palindrome, and print not palindrome if it is not a palindrome.

Space It Out

Given a string quote, add a space between every character, then print out the new quote.

Previous Done
© Tynker, 2020
Sign in
Don't have an account?