In python,
Part 1: Estimate the value of e.
e is defined as  as n goes to infinity. So the largerthe value of n, the closer you should get to e.
math.e is defined as 2.718281828459045
You'll write a program that uses a while loop to estimate e towithin some defined error range, while having a limit on how manyiterations it will attempt.
Part 2: Palindrome detection
A palindrome is a string that is the same forwards andbackwards.
Madam I'm Adam
Racecar
Was it a cat I saw?
There are many sophisticated ways of detecting palindromes. Someare surprisingly simple (s == s[::-1])
You will use a for loop to iterate over the contents of thestring to determine if it is a palindrome.
Beware! There are many solutions online. Don't fall prey tolooking this one up. It's not as hard as it looks. Draw it out onpaper first and think through how you index the string from bothends.
skeleton of code:
#
# Estimate the value of e.
#
# Write a routine that uses a while loop to estimate e.
#
# Arguments:
#Â Â Â Â Â Â delta: How close the estimatehas to come
#Â Â Â Â Â Â n:Â Â Â Â Â Maximum number of attempts
#
# Algorithm:
#Â Â Â Â Â Â Compare math.e to your valueof e and if the difference is
#Â Â Â Â Â Â greater than delta, incrementcount and make a new estimate. A
#Â Â Â Â Â Â Assuming the count variableis \"i\", the formula for e is:
#Â Â Â Â Â Â Â Â Â Â e =(1 + 1/i)**i
#
#Â Â Â Â Â Â Stop when the differencebetween math.e and your value is less
#Â Â Â Â Â Â than delta or the countvariable reaches n.
#
# Output:
#Â Â Â Â Â Â Return a tuple of the deltaand the number of tries you made
#
import math
def estimateE(delta, n):
   pass
#
# Return true if s is a palindrome
#
# Look at the indices of a string s = \"abcdcba\":
#Â Â 0, 1, 2, 3, 4, 5, 6
# -7, -6, -5, -4, -3, -2, -1
#
# To be a palindrome, s[0] == s[-1], s[1] == s[-2], etc
#
# Return True if s is a palindrome
#
# Use ONLY a for loop, len, and slicing.
#
def palindrome(s):
   pass
#
# Don't change the lines below! They run the tests for gradeevaluation!
#
def main():
   print(palindrome(\"abcdef\"))
   print(palindrome(\"abcdcba\"))
   print(palindrome(\"abba\"))
   print(palindrome(\"abccba\"))
   r = estimateE(0.01, 10)
   print(\"{0:6.4}\".format(r[0]), r[1]) # Prints0.1371, 10
   r = estimateE(0.01, 100)
   print(\"{0:6.4f}\".format(r[0]), r[1]) # Prints0.0136, 100
   r = estimateE(0.01, 1000)
   print(\"{0:6.4f}\".format(r[0]), r[1]) # Prints0.0100, 136
 Â
#
# Only run testcases if this is main
#
if __name__ == \"__main__\":
   main()