Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sigma, pi, exercise
#1
Photo 
Write programs (for and while) that calculate the sum (product) (using inconditional statement, omit elements that generate the error)

The print statement in each loop should beoutput a string containing the value of the loop counter, the value of the element (in the case of error generating elements, the string ——) and the current one value of the sum (product) with a precision of 5 digits after the decimal point.

Well any advices, i just dont know how to implement that if there are negative numbers, also when cosinus showed up.

I want to implement it in PYTHON.
My code so far:
N=13
s = -4
    for i in range(-4, n+1):
        
        total *= s + 5 / s + 1
        s = s + 1
     print ("[n==%d] Suma = %s" %(n, total))
and description: [Image: ubvCall.png]
Reply
#2
I am guessing that you want to automate the equations in the picture?
In that case the 7 lines of code presented need some serious work:
- Uppercase != lowercase
- Indentation
- line 5 has some issues with operations priority (looking at the picture)
- Index i is not used, but i think it needs to be
- why define s as -4 and use it in another way....
Suggestions to start with:
- Use N(n?) and s for their purpose
-Get the indentation right
-Check line 5 for operations order.
-Initiate total
Paul
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020