What is wrong with my python code?

Hello. I want to write code for sequences below but it doesn’t work. WHat is wrong ? Could you help me

Code is;

import math
def un(n_terms):
  def vn(n_terms):
    p = 0
    sum_un = 0
    while n_terms>=1:
      while p<=n_terms:
        sum_un = sum_un + (1//math.factorial(p))
        p = p + 1
    un(n_terms) = sum_un
    vn(n_terms) = un(n_terms) + (1//(n_terms * math.factorial(n_terms)))
  print(vn(10))
print(un(10))
#!/usr/bin/env python3 
import math
def un(n_terms):
  def vn(n_terms):
    p = 0
    sum_un = 0
    while n_terms>=1:
      while p<=n_terms:
        sum_un = sum_un + (1//math.factorial(p))
        p = p + 1
    un(n_terms) = sum_un
    vn(n_terms) = un(n_terms) + (1//(n_terms * math.factorial(n_terms)))
  print(vn(10))
print(un(10))

with tabs

why it doesnt post with tabs idk

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

thank you very much.

Hello mimi.

If your code is as you have pasted it, then you have an infinite loop, because n_terms is always >= 1.

Also, that is a very odd way to have written the code; having two functions is cluttered and unnecessary.

I would start from scratch, and rework through the logic of the problem. After you try that, let me know if you get stuck.

I hope that helps.

i dont know what the exact problem is but its on the 10th line in your code.
the code is: un(n_terms) = sum_un