Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3.2
- # -*- coding: utf-8 -*-
- # main.py
- """ Task: Exercise 6.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.
- fruit = 'banana'
- index = 0
- while index < len(fruit):
- letter = fruit[index]
- print(letter)
- index = index + 1
- """
- ''' Main '''
- fruit = 'banana'
- index = len(fruit) - 1
- while index >= 0:
- letter = fruit[index]
- print(letter)
- index -= 1
- fruit = 'B' + fruit[1:]
- print(fruit[:]) # Exercise 6.2, output: 'Banana'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement