Aim:
Using a for loop, write a program that prints out the decimal equivalents of 1/2, 1/3, 1/4, .
1/10.
Description:
A loop statement allows us to execute a statement or group of statements multiple times. We
can use for loop to calculate the decimal equivalents of given set of numbers.
for loop statement:
It has the ability to iterate over the items of any sequence, such as a list or a string. Iterating
over a sequence is called Traversal. The general form of for loop statement is as follows:
for iterating_var in sequence:
Statement(s)
To find the decimal equivalents, we need to use the method pow(). This method is not
accessible directly, so we need to import math module and then we need to call this method using
math static object.
Algorithm:
Output: Decimal equivalents of 1/2, 1/3, .. ,1/10
Step1: Start
Step2: Import math module
Step3: Initialize i = 2
Step4: Repeat Steps 5,6 until i = 11
Step5: Print math.pow(i,-1)
Step6: Increment i by 1
Step7: Stop
Program:
print("Decimal Equivalents of:")
No comments