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.3
- Encapsulate this code in a function named count, and generalize it so that
- it accepts the string and the letter as arguments.
- word = 'banana'
- count = 0
- for letter in word:
- if letter == 'a':
- count = count + 1
- print(count)
- """
- ''' Functions '''
- def count(word, letter):
- count = 0
- for letter in word:
- if letter == 'a':
- count += 1
- return count
- ''' Test '''
- word = 'banana'
- count = count(word, 'a')
- print(count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement