In: Computer Science
Create a new Python 3 Jupyter Notebook.
At the top, be sure to name your notebook as "*assignment 2.08 - Your Name Here.ipynb*" (obviously, replace the "Your Name Here" part with your actual name).
Create a single python cell to program the following specifications.
Use what you've learned on this page to:
1. Find the index of "lmno" in the English alphabet using an
appropriate instruction and store it in a variable. (hint: you'll
need to define a string that contains the letters of the alphabet
in their proper order)
1. Find the length of "lmno" using an appropriate instruction and
store it in a different variable.
1. Use those two variables to determine the index for the end of
"lmno" within the alphabet and store that in a third variable.
(hint: use math)
1. Use the two variables that are defined as indexes to get the
corresponding slice of the alphabet and print it out using a format
string.
You may use any other variables you determine are necessary or helpful. Also, be sure to use comments as needed to explain what is taking place.
alphabet = "abcdefghijklmnopqrstuvwxyz" #string that contains all the alphabets
#In first line I created a variable alpahbet and stored alphabets in order
#1.finding the index of the substring "lmno" in alphabet string
using find() function. stringname.find(substring)
index1 = alphabet.find("lmno") #finds the substring "lmno" in the
string alphabet and stores in index1
#1.finding the length of the word "lmno". Here I used len()
function.
length = len("lmno") #finds length of the string "lmno"
#1.Next I have to find the index for the end of word "lmno" in string alphabet. So, I just added the initial index where I found it(index1). And then I used length of the word to find the end index. (index1+length)=end index
index2 = index1+length #adding the index1 (position of the string)
and length of the string to get last index of
# the word
#Now Using two indexes I have to print the slice of string using
format string. Here format(word) prints the word in the statement
where {} are placed. And alphabet[index1:index2] slices the string
from index1 to index2
print("The corresponding slice of the alphabet is
{}".format(alphabet[index1:index2])) #printing the sliced
# alphabet using a format string
If you have any doubt comment me.