Practice Exercises - Lab 8 (Recursion)
Practice Exercises - Lab 8 (Recursion)
1, if x = 1
x + sum from 1 to x-1 if x > 1
def main():
# compute and print 1 + 2 + ... + 10
print sum(10)
def sum(x):
# you complete this function recursively
main()
2. Revise the Fibonacci program so that it asks the user for which
Fibonacci number he or she wants. Then use this value to instead
of 6 in the program. Use your program to compute the 10th, 20th,
30th and 40th Fibonacci numbers. Why does it take so much
longer to computer the higher Fibonacci numbers?
(OVER)
Implement this recursive algorithm in Python and test it using a
main function that calls this with the values 15, 105, and 15105.
(HINT: Remember that if n is an integer, n/10 will be an integer
without the fractional part.)