Computer Science, asked by shannu9104, 1 year ago

Using a for loop, write a program that prints out the decimal equivalents of 1/2, 1/3, 1/4,..., 1/10. in python

Answers

Answered by qwtiger
19

Answer:

The code is for : Using a for printing the sequence that prints out the decimal equivalents of 1/2, 1/3, 1/4,..., 1/10. in python

Explanation:

n=int(input("Enter the number of terms: "))

sum1=0

for i in range(1,n+1):

sum1=sum1+(1/i)

print("The sum of series is",round(sum1,2))

Answered by AskewTronics
1

The python program for the above question is as follows:

Explanation:

for x in range(2,11): #for loop which runs for the value of x of 2 to 10

  print(1/x,end =", ") # print the decimal value for every iteration of for loop after divide the 1 by x value.

Output:

The output of the above program is--- 0.5, 0.3333333333333333, 0.25, 0.2, 0.16666666666666666, 0.14285714285714285, 0.125, 0.1111111111111111, 0.1.

Code Explanation:

  • x variable is used for 'for' loop which value lies in between to 2 to 10(The first value of x is 2 and the last value of x is 10).
  • Then the print statement is used to print the value after dividing 1 by x value separated by ',' as the question suggests.

Learn More:

  • For Loop : https://brainly.in/question/8823865
  • Loop : https://brainly.in/question/14673533

Similar questions