sum of 1 2 2 3 3 4 n n 1

+4 votes
Write a program to compute 1/2+2/3+3/4+...+n/n+1 with a given n input by console (n>0).

Example: If the following n is given as input to the program: 5

Then, the output of the program should be: 3.55
Dec 21, 2019 in Python by DhineshBabu
• 160 points
13,147 views

2 answers to this question.

+3 votes
num = int(input("Enter a number: "))
newnum = 0

for each in range(1,num+1):
    newnum = newnum+(each/(each+1))

print("computed value : ",format(round(newnum,2)))
answered Dec 27, 2019 by Nisha
• 200 points
Nisha,

Can You please explain, how it works ?

how come 3.55 is coming up ?

Please

Komal S Patel

+447534288877
Hey, @Komal,

While executing this code I am getting the exact output that is required. If you are facing any error please post that.
This prog. is right and in last format you can write and not that doesn't make any change.
–1 vote
n=int(input("Enter the number of terms: "))

sum=0

for i in range(1,n+1):
    sum=sum+(i/(i+1))

print("The sum of series is: ",round(sum,2))
answered Sep 28, 2020 by anonymous
• 140 points

Related Questions In Python

0 votes
1 answer

What will be the output of below code and why? x=[1,2,3,4,5] print(x.insert(2,3))

If you write x.insert(2,3) and then print x ...READ MORE

answered Oct 14, 2020 in Python by Gitika
• 65,770 points
4,361 views
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 5, 2018 in Python by Omkar
• 69,220 points

edited Aug 8, 2018 by Omkar 8,149 views
+4 votes
3 answers

Write a for loop that prints all elements of a list and their position in the list. a = [4,7,3,2,5,9]

Try using this question by list comprehension: a=[4,7,3,2,5,9] print([x for ...READ MORE

answered Dec 9, 2019 in Python by vinaykumar
• 200 points
34,852 views
0 votes
1 answer

what is the output of m = np.array([2,4,6]) n = np.array([2, True, False]) print(m+n)

Hi. @Nandini, The above code will give you ...READ MORE

answered Nov 11, 2020 in Python by Gitika
• 65,770 points
512 views
0 votes
1 answer

Create 3*4 array of random numbers - Python

To create different arrays like random arrays:  np.random.rand(3,4) ...READ MORE

answered May 24, 2019 in Python by Umer
1,780 views
0 votes
1 answer

How do I create 3 X 4 array of random numbers between 0 and 100 using python?

Use numpy in the following manner: np.random.rand(3,4)*100 When you ...READ MORE

answered May 24, 2019 in Python by Radhika
2,258 views
0 votes
1 answer

Sum of prime numbers from m to n in python

def is_prime(number):     if number < 2:         return False     for i ...READ MORE

answered Jan 5 in Python by Ali
824 views
0 votes
1 answer

Install pip in Python 3.4

Don't worry! Python already comes in default ...READ MORE

answered May 1, 2018 in Python by aayushi
• 750 points
3,420 views
0 votes
1 answer

What is the meaning of “int(a[::-1])” in Python?

Assumming a is a string. The Slice ...READ MORE

answered Aug 27, 2018 in Python by Priyaj
• 58,020 points
6,471 views
0 votes
1 answer

How is Python 2.7.3 and Python 3.3 different?

raw_input() is not used in Python 3. Use input()  ...READ MORE

answered Sep 12, 2018 in Python by SDeb
• 13,300 points
924 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP