0
Do we need to find the terms of number if we code this?
If the series is 1/3+3/5+5/7+....+95/97+97/99 sum = 0 for i in range(1,100,2) : for s in range(1,i+1): sum += ((1)+(3))+ (5) print("i = ",i,", ","sum is =", sum) sum = 0 What's wrong with this?
8 Respuestas
+ 4
I have given you the hint so now you should give it a try to write a code on your own. If you got any error then you can share it over here. We would definitely try to help you.
+ 4
sumaiya sharmin check whether this code works or not.
sum = 0
for i in range(1,100,2):
sum += i/(i+2)
print("i = ",i,", ","sum is =", sum)
+ 3
For the series that you have mention the methods would be
(Numerator + 1)/2 = nth term
(Denominator - 1)/2 = nth term
+ 1
To get the numbers for your term you can use a range object like: range(1,100,2) which gives you the numbers 1,3,5,... For the calculation it depends if you have to calculate with fractions or with a division.
+ 1
sum = 0
for i in range(1,98,2):
sum += i/(i+2)
print("i = ",i,", ","sum is =", sum)
+ 1
The mistake in your code is that you are always adding (1+3+5) i.e 9 on every loop... Thus leading to wrong answer:
The correct solution would be as simple as this :
https://code.sololearn.com/c5aG5zMwymSR/?ref=app
0
So the code would be?
0
Sure