# Class notes from Thursday, April 19

# printletters takes a string as input and prints out the individual characters
# of the string

def printletters(word):
    i = 0
    while i < len(word):
        print word[i]
        i = i + 1
    print "done"

# >>> printletters("apple")
# a
# p
# p
# l
# e
# done
# >>>

#-----------------------------------------------------------------------------------
# There are several different data types available in Python:
#
# Type   Description               Examples
# int    integers (whole numbers)  7  42  -517  1024
# float  floating-point numbers    3.14159  -0.12345  542.0
# str    strings                   'apple'  'Hello, world!'  '342'
# bool   boolean values            True  False
# list   lists of values           [10, 20, 30]   ['mom', 'baseball', 'apple', 3.14]
#
# These type names can be used as functions to convert between types.  Examples:
#
# str(542) => '542'
# str(3.14159) => '3.14159'
# float(542) => 542.0
# int('542') => 542
# float('542') => 542.0
# int('3.14') => ERROR (the string '3.14' does not represent a valid integer)
# int(3.14159) => 3
# list("apple") => ['a', 'p', 'p', 'l', 'e']
# 542 + 10 => 552
# str(542) + str(10) => '54210'
# str(542) + 10 => ERROR (you can't add a string to a number)

#-----------------------------------------------------------------------------------

# printdigits takes a number as input and prints outs the individual digits

def printdigits(number):
    digits = str(number)
    i = 0
    while i < len(digits):
        print digits[i]
        i = i + 1
    print "done"

# >>> printdigits(78542)
# 7
# 8
# 5
# 4
# 2
# done
# >>>

# sumdigits takes a number as input and returns the sum of all the digits

def sumdigits(number):
    digits = str(number)
    sum = 0
    i = 0
    while i < len(digits):
        d = digits[i]
        sum = sum + int(d)
        i = i + 1
    return sum

# >>> sumdigits(78542)
# 26
# >>>

