- Exercise 1: Write a while loop that starts at the last character in the string and works its way backwards to the first character in the string, printing each letter on a separate line, except backwards.
cha=input('Enter a word:')
index=len(cha)-1while index>=0:
letter=cha[index]print(letter)
index =index-1
- Exercise 3: Encapsulate this code in a function named count, and generalize it so that it accepts the string and the letter as arguments.
word=input('Enter a word:')
letter=input('Enter a letter:')defcount(word,letter):
jishu=0for ci in word:if letter is ci:
jishu=jishu+1print(jishu)
count(word,letter)
- Exercise 4: Write an invocation that counts the number of times the letter a occurs in “banana”.
fruit="banana"print(fruit.count('a'))
- Exercise 5: Take the following Python code that stores a string:
str = ‘X-DSPAM-Confidence:0.8475’
Use find and string slicing to extract the portion of the string after the colon character and then use the float function to convert the extracted string into a floating point number.
- Exercise 1: Write a while loop that starts at the last character in the string and works its way backwards to the first character in the string, printing each letter on a separate line, except backw...