sum of 1 2 2 3 3 4 n n 1

+1 vote
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
• 130 points
5,541 views

2 answers to this question.

+2 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
• 180 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.
0 votes
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
• 150 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,870 points
609 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 4, 2018 in Python by Omkar
• 69,090 points

edited Aug 8, 2018 by Omkar 5,300 views
+2 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 8, 2019 in Python by vinaykumar
• 180 points
11,682 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,870 points
43 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
113 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
269 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
952 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,100 points
478 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,250 points
166 views
0 votes
1 answer

Python 3 equivalent of SimpleHTTPServer

The SimpleHTTPServer module has been merged into ...READ MORE

answered Nov 20, 2018 in Python by SDeb
• 13,250 points
246 views