SlideShare a Scribd company logo
1 of 7
Lecture Two
What we want to install in bioinformatics LAB ?
1.Python 2.7.x or later.
2.Biopython.
To learn how to use Biopython we must first know how to use python
commands
let us start to download it to PCs LAB:
If our PCs has windows as an operating system then we go to this location
https://www.python.org/ and install python on the windows.
After installation let us enter to some simple instruction that may be help us
to understand python language :
Variables and Some Arithmetic
In Python the basic data types are strings and numbers.
Example:
a=324
b = 24
c = a - b
print 'a - b is', c
output:
a - b is 300
You can now use all common arithmetic operations involving numbers:
•Addition: 2 + 3 == 5
•Subtraction: 5 - 2 == 3
•Multiplication: 3 * 4 == 12
•Division: 15 / 3 == 5
•Division remainder: 18 % 5 == 3
•Exponentiation: 2 ** 3 == 8
It is important to note that if you try to divide two integers,
Python always rounds down the result
(so 18/5 == 3).
To obtain a precise result for this division, you need to
indicate floating point division in either of the following
expressions:
•18.0/5 == 3.6
•float(18)/5 == 3.6
In Python, the single equals sign (=) means "assign a value
to a variable". For example, a = 3 assigns 3 to the integer a. In
order to denote equality, Python uses the double equals sign
(==).
In Python, a string is an ordered sequence of letters,
numbers and other characters. You can create string variables
just like you did with :
a = "Hello"
b = "World"
Notice that the string must be surrounded by " or ' (but not a
mix of both). You can use quotes inside the string, as long as you
use the opposite type of quotes to surround the string e.g.:
a = "Learning Python" or
b = 'Project "Bioinformatics"'.
String operations differ slightly from operations on numbers:
a = 'Bioinformatics'
b = 'LAB'
c = '!'
print a + ' ' + b + c*3
Output:
Bioinformatic LAB!!!
Get input from user: get an input from user and put it in var.
var = raw_input(">>> ")
Given: Two positive integers a and b, each less than 1000.
Return: The integer corresponding to the square of the hypotenuse of the
right triangle whose legs have lengths a and b.
var1 = raw_input(">>> ")
var2 = raw_input(">>> ")
r=(int)var1 ** 2 +(int)var2 ** 2
print 'The result is' ,r
In the above example why we use (int) and what happened if we leave it
try it by yourself.(H.W.)
Strings and lists:
We've already seen numbers and strings, but Python also has variable
types that can hold more than one piece of data at a time. The simplest
such variable is a list.
You can assign data to a list in the following way:
list_name = [item_1, item_2, ..., item_n].
The items of the list can be of any other type: integer, float, string.
You even explore your inner Zen and make lists of lists!
What is Zen?(H.W.)
Any item in a list can be accessed by its index, or the number that
indicates its place in the list. For example, try running the following
code:
tea_party = ['March Hare', 'Hatter', 'Dormouse', 'Alice']
print tea_party[2]
Your output should be:
Dormouse
You can easily change existing list items by reassigning them.
Try running the following:
tea_party[1] = 'Cheshire Cat'
print tea_party
You can also add items to the end of an existing list by using
the function append():
tea_party.append('Jabberwocky')
print tea_party
If you need to obtain only some of a list, you can use the notation
list_name[a:b] to get only those from index a up to but not including index
b.
For example, tea_party[1:3]
returns : Cheshire Cat, Dormouse, not Cheshire Cat, Dormouse, Alice. This
process is called "list slicing".
If the first index of the slice is unspecified, then Python assumes that
the slice begins with the beginning of the list (i.e., index 0).
If the second index of the slice is unspecified, then you will obtain the
items at the end of the list.
For example: tea_party[:2]
returns March Hare, Cheshire Cat
tea_party[3:]
returns Alice, Jabberwocky.
You can also use negative indices to count items backtracking from the
end of the list. So tea_party[-2:] returns the same output as tea_party[3:]:
Alice, Jabberwocky.
Finally, Python equips you with the magic ability to slice strings the
same way that you slice lists. A string can be considered as a list of
characters, each of which having its own index starting from 0.
For example: try running the following code:
a = 'flimsy'
b = 'miserable'
c = b[0:1] + a[2:]
print c
This code will output the string formed by the first character of miserable
and the last four characters of flimsy:
mimsy
Given: A string s of length at most 200 letters and four integers a, b, c
and d.
Return: The slice of this string from indices a through b and c through d
(with space in between), inclusively.
Solution:
s=HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntpu
tHumptyDumptyinhisplaceagain.
a=22
b=27
c=97
d=102
x=s[a:b+1]+' '+s[c:d+1]
print x
The output should be:
Humpty Dumpty
Prepared by Suhad Jihad using http://rosalind.info/problems/locations/ as a main
reference.
print c
This code will output the string formed by the first character of miserable
and the last four characters of flimsy:
mimsy
Given: A string s of length at most 200 letters and four integers a, b, c
and d.
Return: The slice of this string from indices a through b and c through d
(with space in between), inclusively.
Solution:
s=HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntpu
tHumptyDumptyinhisplaceagain.
a=22
b=27
c=97
d=102
x=s[a:b+1]+' '+s[c:d+1]
print x
The output should be:
Humpty Dumpty
Prepared by Suhad Jihad using http://rosalind.info/problems/locations/ as a main
reference.

More Related Content

What's hot (20)

Strings
StringsStrings
Strings
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
Pytho_tuples
Pytho_tuplesPytho_tuples
Pytho_tuples
 
Python lists
Python listsPython lists
Python lists
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming language
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
Pytho dictionaries
Pytho dictionaries Pytho dictionaries
Pytho dictionaries
 
1. python
1. python1. python
1. python
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expression
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
Pytho lists
Pytho listsPytho lists
Pytho lists
 
Assignment statements
Assignment statementsAssignment statements
Assignment statements
 
String in python lecture (3)
String in python lecture (3)String in python lecture (3)
String in python lecture (3)
 
Python List Comprehensions
Python List ComprehensionsPython List Comprehensions
Python List Comprehensions
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 

Similar to Introduction to biopython

Similar to Introduction to biopython (20)

Python Basics
Python BasicsPython Basics
Python Basics
 
MODULE. .pptx
MODULE.                              .pptxMODULE.                              .pptx
MODULE. .pptx
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Day2
Day2Day2
Day2
 
Python.pdf
Python.pdfPython.pdf
Python.pdf
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Python slide.1
Python slide.1Python slide.1
Python slide.1
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptx
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
 
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Notes3
Notes3Notes3
Notes3
 
Arrays
ArraysArrays
Arrays
 

Recently uploaded

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Recently uploaded (20)

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

Introduction to biopython

  • 1. Lecture Two What we want to install in bioinformatics LAB ? 1.Python 2.7.x or later. 2.Biopython. To learn how to use Biopython we must first know how to use python commands let us start to download it to PCs LAB: If our PCs has windows as an operating system then we go to this location https://www.python.org/ and install python on the windows. After installation let us enter to some simple instruction that may be help us to understand python language : Variables and Some Arithmetic In Python the basic data types are strings and numbers. Example: a=324 b = 24 c = a - b print 'a - b is', c output: a - b is 300 You can now use all common arithmetic operations involving numbers: •Addition: 2 + 3 == 5 •Subtraction: 5 - 2 == 3 •Multiplication: 3 * 4 == 12 •Division: 15 / 3 == 5 •Division remainder: 18 % 5 == 3
  • 2. •Exponentiation: 2 ** 3 == 8 It is important to note that if you try to divide two integers, Python always rounds down the result (so 18/5 == 3). To obtain a precise result for this division, you need to indicate floating point division in either of the following expressions: •18.0/5 == 3.6 •float(18)/5 == 3.6 In Python, the single equals sign (=) means "assign a value to a variable". For example, a = 3 assigns 3 to the integer a. In order to denote equality, Python uses the double equals sign (==). In Python, a string is an ordered sequence of letters, numbers and other characters. You can create string variables just like you did with : a = "Hello" b = "World" Notice that the string must be surrounded by " or ' (but not a
  • 3. mix of both). You can use quotes inside the string, as long as you use the opposite type of quotes to surround the string e.g.: a = "Learning Python" or b = 'Project "Bioinformatics"'. String operations differ slightly from operations on numbers: a = 'Bioinformatics' b = 'LAB' c = '!' print a + ' ' + b + c*3 Output: Bioinformatic LAB!!! Get input from user: get an input from user and put it in var. var = raw_input(">>> ") Given: Two positive integers a and b, each less than 1000. Return: The integer corresponding to the square of the hypotenuse of the right triangle whose legs have lengths a and b. var1 = raw_input(">>> ") var2 = raw_input(">>> ") r=(int)var1 ** 2 +(int)var2 ** 2 print 'The result is' ,r In the above example why we use (int) and what happened if we leave it try it by yourself.(H.W.)
  • 4. Strings and lists: We've already seen numbers and strings, but Python also has variable types that can hold more than one piece of data at a time. The simplest such variable is a list. You can assign data to a list in the following way: list_name = [item_1, item_2, ..., item_n]. The items of the list can be of any other type: integer, float, string. You even explore your inner Zen and make lists of lists! What is Zen?(H.W.) Any item in a list can be accessed by its index, or the number that indicates its place in the list. For example, try running the following code: tea_party = ['March Hare', 'Hatter', 'Dormouse', 'Alice'] print tea_party[2] Your output should be: Dormouse You can easily change existing list items by reassigning them. Try running the following: tea_party[1] = 'Cheshire Cat' print tea_party You can also add items to the end of an existing list by using the function append():
  • 5. tea_party.append('Jabberwocky') print tea_party If you need to obtain only some of a list, you can use the notation list_name[a:b] to get only those from index a up to but not including index b. For example, tea_party[1:3] returns : Cheshire Cat, Dormouse, not Cheshire Cat, Dormouse, Alice. This process is called "list slicing". If the first index of the slice is unspecified, then Python assumes that the slice begins with the beginning of the list (i.e., index 0). If the second index of the slice is unspecified, then you will obtain the items at the end of the list. For example: tea_party[:2] returns March Hare, Cheshire Cat tea_party[3:] returns Alice, Jabberwocky. You can also use negative indices to count items backtracking from the end of the list. So tea_party[-2:] returns the same output as tea_party[3:]: Alice, Jabberwocky. Finally, Python equips you with the magic ability to slice strings the same way that you slice lists. A string can be considered as a list of characters, each of which having its own index starting from 0. For example: try running the following code: a = 'flimsy' b = 'miserable' c = b[0:1] + a[2:]
  • 6. print c This code will output the string formed by the first character of miserable and the last four characters of flimsy: mimsy Given: A string s of length at most 200 letters and four integers a, b, c and d. Return: The slice of this string from indices a through b and c through d (with space in between), inclusively. Solution: s=HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntpu tHumptyDumptyinhisplaceagain. a=22 b=27 c=97 d=102 x=s[a:b+1]+' '+s[c:d+1] print x The output should be: Humpty Dumpty Prepared by Suhad Jihad using http://rosalind.info/problems/locations/ as a main reference.
  • 7. print c This code will output the string formed by the first character of miserable and the last four characters of flimsy: mimsy Given: A string s of length at most 200 letters and four integers a, b, c and d. Return: The slice of this string from indices a through b and c through d (with space in between), inclusively. Solution: s=HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntpu tHumptyDumptyinhisplaceagain. a=22 b=27 c=97 d=102 x=s[a:b+1]+' '+s[c:d+1] print x The output should be: Humpty Dumpty Prepared by Suhad Jihad using http://rosalind.info/problems/locations/ as a main reference.