Question

In: Computer Science

Two coding challenges this week! Part 1: Estimate the value of e. e is defined as  as...

Two coding challenges this week!

Part 1: Estimate the value of e.

e is defined as  as n goes to infinity. So the larger the 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 to within some defined error range, while having a limit on how many iterations it will attempt.

Part 2: Palindrome detection

A palindrome is a string that is the same forwards and backwards.

Madam I'm Adam
Racecar
Was it a cat I saw?

There are many sophisticated ways of detecting palindromes. Some are surprisingly simple (s == s[::-1])

You will use a for loop to iterate over the contents of the string to determine if it is a palindrome.

Beware! There are many solutions online. Don't fall prey to looking this one up. It's not as hard as it looks. Draw it out on paper first and think through how you index the string from both ends.

Solutions

Expert Solution

A you didn't mentioned the programing language i did it in python

#pyhton program to find the value of e upto n decimal points

import decimal

#find the factorial of n numbers
def fact(a):
fac = [1]
for i in range(1, a + 1):
fac.append(fac[i - 1] * i)
return fac

# calculating the value of e upto n numbers
def value_of_e(a):
decimal.getcontext().prec = a + 1
e = 2
fac = fact(2 * a + 1)
for i in range(1, a + 1):
c = 2 * i + 2
d = fac[2 * i + 1]
e += decimal.Decimal(c / d) #formula to find the decimal values of e
return e

#using while loop to print the value of e upto n numbers
while True:
a = int(input("Enter the decimal points after 2 in e : "))
if a >= 0:
break

print(str(value_of_e(a))[:a + 1])

2 .

Program to find the given string is a pallindrome or not

a = input("Enter the string : ") #Enter the string
b = "" #Create an empty array
#finding the given string is a palindrome or not using a for loop
for j in a:
b = j+b
print("the string in reverse order is : ",b)
if (a==b):
print ("The entered string is a palindrome") #print palindrome if the string is same
else:
print("The entered string isn't a palindrome") #print not a palindrome if the string is different


------------------------------------------------------------------------------------------

Kindly comment your queries if any, upvote if you like it. Thank You!!


Related Solutions

In python, Part 1: Estimate the value of e. e is defined as  as n goes to...
In python, Part 1: Estimate the value of e. e is defined as  as n goes to infinity. So the larger the 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 to within some defined error range, while having a limit on how many iterations it will attempt. Part 2: Palindrome detection A palindrome is a string that is the same forwards and...
Previously, we defined a point estimate as a value of a statistic that estimates the value...
Previously, we defined a point estimate as a value of a statistic that estimates the value of a parameter. For example, a sample mean would estimate a population mean. Do you think most people trust point estimates for things that need to be measured? Why or why not? Please cite examples for your reasoning. Looking back over previous examples, how might adding confidence intervals help managers accept the results?
Obtain an estimate for the value of e by approximating the solution of the following initial...
Obtain an estimate for the value of e by approximating the solution of the following initial value problem at t = 1 y'=y     y0=1     Use a step size of 0.25. Apply Euler’s Method, the Midpoint Method, and the Improved Euler’s Method in order to approximate the solution to this problem. Calculate the absolute relative true percent error using seven significant figures. Calculate this error for each method and only for the last iteration.
The size effect, value effect and day of the week effect represent three empirical challenges to...
The size effect, value effect and day of the week effect represent three empirical challenges to market efficiency hypothesis. Drawing from empirical research evidence, explain how these anomalies challenge the market efficiency hypothesis.
1) A) A point estimate: is a single value estimate for a population [ Select ]...
1) A) A point estimate: is a single value estimate for a population [ Select ] ["statistic", "parameter"] . To estimate the population mean [ Select ] ["µ", "x-bar"] we use the sample mean [ Select ] ["µ", "x-bar"] . To estimate the population proportion [ Select ] ["p", "p-hat"] we use the sample proportion [ Select ] ["p", "p-hat"] . B) The central limit theorem is important in statistics because it allows us to use the Normal distribution to...
Solved parts a-e, need the rest. 1. Suppose the economy can be defined as the following:...
Solved parts a-e, need the rest. 1. Suppose the economy can be defined as the following: Consumption Function: 3000+0.6*(Y-T) Investment Function: 600-50r Government Expenditure = 500; Tax = 500 Net Export = 300–30r M = 10000 Money Demand Function: L(Y,r) =5Y–2500r a) Derive the IS curve. IS: r = 51.25 - .005Y b) Derive the LM curve LM: r = .002Y-4*(1/P) c) Suppose P = 10, compute the equilibrium interest rate and output. (e.g. If you compute r = 2.46,...
Week 1 Assignment Complete this two page assignment by the end of week 1! Download and...
Week 1 Assignment Complete this two page assignment by the end of week 1! Download and open the Word document below....fill in the blank and highlight the answer to the questions or fill in the blank. Resubmit here when you're finished by adding your completed assignment as a file! BIO 212 Assignment 1.docx BIO 212 Assignment 1 Fill in the Blank: Use the table on pg. 848-853 in your textbook to help you fill in the blank. Drug Classification Action...
IFRS 13 Fair Value Measurement 1 Introduction Fair value is defined as the price that would...
IFRS 13 Fair Value Measurement 1 Introduction Fair value is defined as the price that would be received to sell an asset or paid to transfer a liability in an orderly transaction between market participants at the measurement date, also referred to as the willing buyer-willing seller principle. It is important to note that fair value is a market-based measurement and not an entity-specific measurement. This guidance paper expands on the concept of fair value, provides some theoretical information to...
The net present value of an investment is best defined as the 1 current cost if...
The net present value of an investment is best defined as the 1 current cost if the investment is made today. 2 net value received at the end of the investment period. 3 present value of the investment's future cash flows minus the investment's cost. 4 net decrease in value caused by waiting to receive the cash benefit from the investment. 5 value received at the end of the investment period minus the investment's cost.
PART 1: WRITE A PROGRAM THAT TAKES IN TWO INTEGERS VALUE N AND M (USER INPUT)...
PART 1: WRITE A PROGRAM THAT TAKES IN TWO INTEGERS VALUE N AND M (USER INPUT) AND CALCULATES THE NTH FIBONACCI SUM USING RECURSION. EXAMPLE: OLD VERSION 0,1,1,2,3.. USING USER INPUT: 0, N, M ,N+M, (N+M)+M PART 2: WRITE THE SAME PROGRAM USING USER INPUT BUT USING A LOOP IN STEAD OF RECURSION. PYTHON
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT