# Arup Guha
# 7/16/2013
# Solution to SI@UCF Recursion Program

def main():

    # Test Part A
    value = int(input("Enter an integer.\n"))
    print("The sum of its digits is", sumDigits(value))

    # Test Part B
    rows = int(input("How many rows do you want in your star design?\n"))
    printTri(rows, 0)

    n = int(input("How many terms in your sequence?\n"))
    a = int(input("What is the zeroth term?\n"))
    b = int(input("What is the first term?\n"))
    print("The desired term is", genFib(n, a, b))
    
def sumDigits(n):

    # Base case is a single digit
    if n < 10:
        return n

    # Get the last digit and recursively add up the rest
    return n%10 + sumDigits(n//10)

def printTri(n, spaces):

    if n > 0:

        # Recursive call to print the rest.
        printTri(n-1, spaces+1)

        # Last row has spaces number of spaces and 2n-1 stars
        print(" "*spaces, end="")
        print("*"*(2*n-1))

def genFib(n, a, b):

    # Two base cases
    if n == 0:
        return a
    if n == 1:
        return b

    # Fibonacci recursion
    return genFib(n-1, a, b) + genFib(n-2, a, b)
              
main()     
