String Manipulation in Scratch

Strings are either single characters, words or sentences. 
Examples of strings: “A”, “b”, “I like Pi”, “$400”, “(^_^)”, “Sentences etc.”



Variables can store strings 


You can pull out individual letters from a String using this block:
Each letter is part of an index that includes spaces.
In the example above, letter 1 is “a”, letter 2 is “p”, and so forth.
If my phrase were “apple juice” instead, letter six would be a space and letter seven would be a “j”.


Please find and write the correct letters based on these four code prompts:








String Concatenation: This refers to the combination of one or more strings using the “join block.” join(“A”,”B”)=”AB”
                                                                        Write Answer here


String Length: the length of the string is simply the number of characters in it. For example length(“I like Pi”) = 9
Write Answer Here


User Input: When we are designing an application, we need to make choices regarding how our program takes in data from the user (person who is using the application). One way is to ask directly.
   
Once the user has provided a response, it will be held temporarily in the “answer” data block. You can then store it. 



Assignments: 

Find letter 15 of the “Friends, Romans, Countrymen” string:

Join two variables with string data (make this difference from the example)

Get the length of this string “102193801232312132312”:

Take in user input (answer a question of your own choice) and store this in a variable. Find the letter 9 (if it exists) and length. Get another piece of user input and join the two strings. Print your final result. 

Experiment with the arithmetic and string operators. What happens when you try to add two strings together?

Challenge: A Chromosome is being built by four letters (‘A’ - Adenine; ‘T’ - Thymine; ‘G’ - Guanine; ‘C’ - Cytosine). Use the random number generator to manually record values between 1-4 on a piece of paper. Create a legend explaining which letter corresponds to which number (i.e. 1-A; 2-T; 3-G; 4-C). Use the join method to create a new string with your gene (i.e. ATGACCCGT).

No comments

Powered by Blogger.