Python Programing Lab EXERCISE - 3(b)


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:")

for i in range(2,11):
      dec_eq=1/i
      print("1/"+str(i)+"= ",dec_eq)

Output:


No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...