I need to write a python code for the following problem:
-Write functions to ask the user for a positive integer n and and integer x and display the sum of the series:
1+1⁄1!+2⁄2!+3⁄3!+⋯+⁄!
Requirement:
- Input validation.
- Write a function to calculate factorials for a number.
- Write a function to calculate the sum of the series.
- import library are not allowed.
so basically, it needs to ask the user for positive int (n) and positive int (x) to solve 1+1⁄1!+2⁄2!+3⁄3!+⋯+⁄! and then display the sum. it should be two equations I think and no math libraries.
This is the code I have so far:
n = int(input('Enter a positive integer: '))
x = int(input('Enter another positive integer: '))
# n >= 0
fact(x)
I am stuck on how to continue past the user input, should i use a for loop or?
n = int(input('Enter a positive integer: '))
# x = int(input('Enter another positive integer: '))
answer = 1
for i in range (n,0,-1):
result = answer*i
print(n, answer)
so, i figured out how to do just the factorial, but now how do i the rest of the equation?