It is best to use a POGIL approach with the following. In POGIL students work in groups on activities and each member has an assigned role. For more information see https://cspogil.org/Home.
If you work in a group, have only one member of the group fill in the answers on this page. You will be able to share your answers with the group at the bottom of the page.
Many interesting problems involve manipulating sequences of data. Youβve learned about strings before, but this activity provides a more in-depth look at what they can do.
A string is a sequence of characters in single quotes(β) or double quotes ("). Depending on the application, we can treat a string as a single value (e.g., sentence), or we can access individual characters using square brackets (e.g., sentence[0]). We can also use slice notation (e.g., sentece[4:8]) to refer to a range of characters. In fact, all types of sequences (including list and tuple) support indexing and slicing.
Letβs take a look at how the : operator works for slicing a string. Consider the example sentence[m:n]. The value at m is the first character in the slice. It is the same value as sentence[m]. However, the value at n is not the same value as sentence[n]. n is the index after the last character included in the slice.
You can also reference only a single number when creating a slice. The slice [m:] means βfrom the index m to the end.β The slice [:n] means βfrom the beginning to the index just before nβ (i.e., the first n characters).
Finds and replaces the first instance of a substring in a larger string with a different string, changing the original string.
Incorrect! Strings are "immutable", which means that their value is unchanged by methods. Try again.
Finds and replaces the first instance of a substring in a larger string with a different string, returning a changed version of the string but without changing the original string.
Incorrect! replace() replaces all occurrences of the substring, not just the first one. Try again.
Finds and replaces every instance of a substring in a larger string with a different string, changing the original string.
Incorrect! Strings are "immutable", which means that their value is unchanged by methods. Try again.
Finds and replaces every instance of a substring in a larger string with a different string, returning a changed version of the string but without changing the original string.
Correct! replace() replaces all occurrences of the substring, not just the first one. However, it doesnβt change the original string.
You may have noticed that it isnβt possible to call the replace method on dna, but calling it on dna[0] is okay. This is because the βlistβ data type does not include a replace method. However, strings allow you to βfind and replaceβ any text. Keep in mind, however, that string variables donβt change after applying a method. For this reason, strings are referred to as immutable (i.e., the value never changes).
11-9-10: The capitalize method capitalizes the first character of a string. If I wanted to capitalize the first letter of the string name = "robby", and change the value ofname, what line of code would I write?
The code blocks below have been mixed up! Rearrange them so that the program prints βGeorgingtonβ. Watch out - there are three code blocks that are unused in the solution!
If you worked in a group, you can copy the answers from this page to the other group members. Select the group members below and click the button to share the answers.
The Submit Group button will submit the answer for each each question on this page for each member of your group. It also logs you as the official group submitter.