Quiz 4
TC101 (Python Group)
Remember that this will not be graded but you should keep this sheet and your solutions as evidence of work. Email your answers to Ken today (so we keep a record of your code today) and also I recommend you post your code on Github and write on your blog as another blog post evidence.
Use your own computer to write the code. Remember that I trust you and you need to do this honestly to give yourself a good “measure” of your ability to this point. If you complete this later than today, then just complete as quick as you can.
- The number e is an important mathematical constant that is the base of the natural logarithm. It is approximately equal to 2.71828,[1] and is the limit of (1 + 1/n)n as n approaches infinity, an expression that arises in the study of compound interest. It can also be calculated as the sum of the infinite series.
Create a function called euler_calc with a single parameter precision. The value of precision is used to determine when to stop calculating. Your calculation will stop when the two consecutive values estimating e differ by less than precision (remember to use absolute value when calculating the difference between two values here).
En este quiz cree una función que se encarga de realizar el proceso para el numero de Euler, el programa recibe un valor dado por el usuario que se encarga de detener el proceso para determinar el numero.
Como primer paso pedí el valor al usuario para
el programa, en seguida empece a definir la función, agregue el parámetro que debía recibir y lo empece a utilizar, al inicio con un pequeño ciclo que se encarga de detener el proceso del numero de Euler, luego agregue la función factorial según el numero que va almacenando un contador, y con otro contador se guarda el numero uno sobre su factorial según el numero de iteraciones, al final solo imprimí los resultados.
Aquí están los links de donde conseguí información.
Por acá está mi código.
import math
print(“Euler Number”)
stop=int(input(“Por favor dame el numero en el cual quieres que termine la secuencia “))
def euler_calc (parar):
contador=0
otra=0
while(contador<=parar):
f=math.factorial(contador)
otra=otra+1/f
contador=contador+1
return otra
resultado=euler_calc(stop)
print(“El resultado es:”,resultado)
Aquí esta mi enlace a GitHub
Este es el programa en funcionamiento.
#QUIZ04 by carlosdanielmartinezblog is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.