0% found this document useful (0 votes)
2 views2 pages

Lab Unit-1 Programs

The document contains Python programming exercises for computing the distance between two points, printing decimal equivalents of fractions from 1/2 to 1/10, finding the factorial of a number using a while loop, and calculating the sum of prime numbers up to 100. Each exercise includes a sample program and expected output. The document serves as a lab guide for Unit-1 in Python programming.

Uploaded by

dk23mer1r12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Lab Unit-1 Programs

The document contains Python programming exercises for computing the distance between two points, printing decimal equivalents of fractions from 1/2 to 1/10, finding the factorial of a number using a while loop, and calculating the sum of prime numbers up to 100. Each exercise includes a sample program and expected output. The document serves as a lab guide for Unit-1 in Python programming.

Uploaded by

dk23mer1r12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Date:

PYTHON PROGRAMMING
Lab: Unit-1
1. Write a python program to compute distance between two points (x1,y1) and (x2,y2)

#Program:
import math
x1 = int(input("Enter the values x1:"))
x2 = int(input("Enter the values x2:"))
y1 = int(input("Enter the values y1:"))
y2 = int(input("Enter the values y2:"))
print("The value of distance b/w two points as
follows:")
print("x1 coordinate:",x1)
print("x2 coordinate:",x2)
print("y1 coordinate:",y1)
print("y2 coordinate:",y2)
Distance=math.sqrt(pow((x2-x1),2)+pow((y2-y1),2))
print("Distance of two points:”, Distance)
Output:

2. Write a python program to print the decimal equivalents of 1/2, 1/3 ... 1/10
#Program:
i=1
while(i<=10):
print("1/”, i,"=",1/i)
i=i+1
Output:
PYTHON PROGRAMMING

3. Python program find factorial of a number using while loop


# Program:
num=int(input("Enter a number to find factorial: "))
factorial=1;
i=1
if num<0:
print("Factorial does not defined for negative
integer");
elif(num==0):
print("The factorial of 0 is 1");
else:
while(i<=num):
factorial=factorial*i
i=i+1
print(‘factorial of the given number’ , num,’is: ‘)
print(factorial)
Output:

Open with Google Docs

4. Write a python program to print prime numbers sum upto 100


sum1=0
for i in range(2,101):
flag=True
for j in range(2,i):
if i%j==0:
flag=False
break;
if flag==True:
sum1=sum1+i
print("The sum of prime numbers is",'upto',i,'=',sum1)
Output:

You might also like