Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Model 2 Indexing and Slicing Questions (15 min) start time: A string is a sequence of characters in single quotes (') or double quotes ().

image text in transcribed

Model 2 Indexing and Slicing Questions (15 min) start time: 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., dna), or we can access individual characters using square brackets (e.g., dna[0]). We can also use slice notation (e.g., dna[4:8]) to refer to a range of characters. In fact, all types of sequences (including list and tuple) support indexing and slicing. 9. What is the positive index of each character in the dna string? Check your answers above. Python code Shell Output Character: G c G C T dna = 'CTGACGACTT' We Input dna = 'CTGACCGACTT' Index: dna [5] 'G' 10. What is the negative index of each character in the dna string? Check your answers above. dna[10] IndexErrpr: String index out of range len(dna) 10 Character: C T G A C G A C T T dna[:5] CTGAC Index: dna[5:] 'GACTT dna[5:10] 'GACTT Reverse of positive 11. Based on the previous questions, what are dna[2] and dna[-2]? Explain your answers. triplet = dna[2:5] We input the code 12. Explain the IndexError you observed. What is the range of indexes for the dna string? print(triplet) GAC dna [-5] 'G dna[-10] 13. Consider the notation of the operator [m:n] for slicing the string. a. Is the value at m the same as the corresponding index value (i.e., dna [m])? If not, describe what it means. 'C dna[:-5] CTGAC b. Is the value at n the same as the corresponding index value (i.e., dna[n])? If not, describe what it means. dna(-5:] 'GACTT triplet = dna(-4:-1] Input the code c. Explain what it means when only a single number is referenced when creating a slice, such as [m:] or [:n]. print(triplet) NameError: name 'paint' is not defined

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions