Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
10327 views
ubuntu2004
Kernel: Python 3 (system-wide)

Exercise 7.1

Find and print the index of the substring "watch" in the following string.

book_title = 'The blind watchmaker' idx = book_title.find('watch') print(idx)
10

Exercise 7.2

Convert the following string to lowercase.

dna_seq = "TTTTGTATCCTTATATCACAACTCGAAGATTCTTCTTCTGCA" lowercase = dna_seq.lower() print(lowercase)
ttttgtatccttatatcacaactcgaagattcttcttctgca

Exercise 7.3

The following text, stored in the variable tbw_intro, contains two sentences.

  1. Find the index of the full stop at the end of the first sentence and store it in a variable called idx.

  2. Using string slicing with the variable idx, assign the first sentence (with full stop) to the variable sentence1.

  3. Again using string slicing and idx, assign the second sentence (with full stop) to the variable sentence2.

  4. Print both sentences separately.

tbw_intro = "We animals are the most complicated things in the known universe. The universe that we know, of course, is a tiny fragment of the known universe." idx = tbw_intro.find('.') sentence1 = tbw_intro[:idx+1] sentence2 = tbw_intro[idx+2:] print(sentence1) print(sentence2)
We animals are the most complicated things in the known universe. The universe that we know, of course, is a tiny fragment of the known universe.