Do we need to find the terms of number if we code this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

28th Apr 2020, 11:25 AM
sumaiya sharmin
sumaiya sharmin - avatar
8 Answers
+ 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.
28th Apr 2020, 11:45 AM
...
+ 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)
28th Apr 2020, 11:57 AM
...
+ 3
For the series that you have mention the methods would be (Numerator + 1)/2 = nth term (Denominator - 1)/2 = nth term
28th Apr 2020, 11:42 AM
...
+ 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.
28th Apr 2020, 11:46 AM
Lothar
Lothar - avatar
+ 1
sum = 0 for i in range(1,98,2): sum += i/(i+2) print("i = ",i,", ","sum is =", sum)
28th Apr 2020, 12:15 PM
sumaiya sharmin
sumaiya sharmin - avatar
+ 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
29th Apr 2020, 6:12 AM
$layer
$layer - avatar
0
So the code would be?
28th Apr 2020, 11:43 AM
sumaiya sharmin
sumaiya sharmin - avatar
0
Sure
28th Apr 2020, 11:46 AM
sumaiya sharmin
sumaiya sharmin - avatar