The document contains a series of practical programming exercises in Python, covering various topics such as calculating squares, sums, averages, HCF, LCM, factorials, and reading from files. Each practical includes code snippets that demonstrate the implementation of the tasks. Additionally, there are exercises for checking number signs, calculating areas and circumferences of circles, generating Fibonacci series, and working with random selections from lists.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
7 views13 pages
Practical No.
The document contains a series of practical programming exercises in Python, covering various topics such as calculating squares, sums, averages, HCF, LCM, factorials, and reading from files. Each practical includes code snippets that demonstrate the implementation of the tasks. Additionally, there are exercises for checking number signs, calculating areas and circumferences of circles, generating Fibonacci series, and working with random selections from lists.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13
Practical-01
#WAP to find the square of first 10
integers. for i in range(1, 11): square = i * i print(square) Practical-02
#WAP to add 2 no.s using functions
with arguments. def add(): a=int(input("enter a value of a:")) b=int(input("enter a value of b:")) c=a+b print("the sum is:",c) Practical-03 #Write a user defined function to cal. the sum and avg of three No.s taken as parameters. def add(a,b,c): p=a+b+c print("the sum is:",p) avg=p/3 print("the avg is:",avg) x=int(input("enter a value of a:")) y=int(input("enter a value of b:")) z=int(input("enter a value of c:")) add(x,y,z) Practical-04
#WAP in python to read first 5
characters from the file("data.txt") f=open("data.txt",n) l=f.read(5) print(l) Practical-05 #WAP to calculate HCF and LCM, 1 cm factoeial using three different functions and called them in main program according to user choice. def HCF(a,b,LCM): HCF=(a*b)/LCM return HCF def LCM(a,b,HCF): LCM=(a*b)/HCF return LCM def fact(n): for i in range(n): fact=fact*i return fact Practical-06
#WAP to calculate sum of two numbers
without using parameters by the user- defined function. def add(): a=int(input("enter a value of a:")) b=int(input("enter a value of b:")) c=int(input("enter a value of c:")) d=int(input("enter a value of d:")) e=int(input("enter a value of e:")) f=a+b+c+d+e print("the sum is",f) Practical-07
#WAP to check if the number is
positive,negative or zero display an appropriate message. n=float(input("enter a number:")) if n==0: print("zero") elif n>=0: print("positive number") else: print("negative number") Practical-09
#import random PICK='random randiant(1,3)' CITY=["Delhi","Mumbai","Chennai","Kolkata"] for i in CITY: print(i,end=" ") print() Practical-10
#WAP to find a factorial of a number
entered by user. int main(): int x,fact=1,n; print("Enter a number:"); scanf("%d",&n); for(x=1;x<=n;x++) fact=fact*x; printf("Factorial of %d is: %d",n,fact); return 0; Practical-11
#wap to calculate area of circle,
diameter of circle and circumference of circle by choice entered by user. r=int(input("enter a radius of a circle:")) d=r/2 area=3.14*r*r circ=2*3.14*r print("diameter is",d) print("area is",area) print("circumference is",circ) Practical-12
#WAP to find fibonacci series of first 11
numbers. num = 10 n1, n2 = 0, 1 print("Fibonacci Series:", n1, n2, end=" ") for i in range(2, num): n3 = n1 + n2 n1 = n2 n2 = n3 print(n3, end=" ") print() Practical-13
#WAP in python to read the first line
from the file ("data,txt"). f=open("data.txt",'n') l=f.readline() print(l) Practical-15
# 2nd random import
SEL="randomrandiant(1,3)" ANIMAL=["Lion","Tiger","Zebra","Spock"] for i in ANIMAL: print(i,end='') print()