PYTHON Lab File
PYTHON Lab File
Program: -
a= [1,3,5,6,7, [3,4,5],"hello"]
print(a)
a. insert (3,20)
print(a)
a. removes (7)
print(a)
a. appends ("hi")
print(a)
Len(a)
print(a)
a.pop (6)
print(a)
a. clear ()
print(a)
output: -
1|Page
2|Page
PROGRAM-2
Aim: -
A) Write a python program to add two numbers.
Program: -
output: -
3|Page
PR
PROGRAM-3 date -
Aim: -
A) Write a program to double a given number and add two
numbers using lambda ()?
Program: -
double = lambda x:2*x
print (double (5))
add = lambda x, y:x+y
print (add (5,4)
output: -
4|Page
PROGRAM-4
Aim: -
A) Demonstrate a python code to implement abnormal
termination?
Program: -
a=15
b=5
print(a/b)
output: -
date -
5|Page
PROGRAM-5
Aim: -
Program: -
import sys
[GCC 9.3.0]
G
System version is:
System version is:
System version is:
System version is:
3.8.2 (default, Mar 13 2020, 10:14:16)
date -
6|Page
PROGRAM-6
Aim: -
Program: -
import datetime
a=datetime. datetime. today ()
b=datetime.datetime.now ()
print(a)
print(b)
output: -
7|Page
PROGRAM-7 date -
Aim: -
import pandas as pd
one=pd. Data Frame ({'Name’:
['SAROJ','PREETI','SHASHI'],
'age’: [19,20,22]},
index= [1,2,3])
two=pd. Data Frame ({'Name’:
['KAJAL','VARSHA','DEEPIKA'],
'age’: [20,21,23]},
index= [4,5,6])
print (pd. concat ([one, two]))
output: -
8|Page
PROGRAM-8
Aim: -
A) Write a python code to set background color and pic and draw a circle
using turtle module
Program: -
1. #Python Program to draw a circle filled with colour in Turtle
2. import turtle
3. ttl = turtle. Turtle ()
4.
5. #Providing the colour to be filled
6. ttl. Color("green")
7.
8. #Instructing to "begin" and "end" filling the "circle"
9. ttl. begin fill ()
10. ttl. Circle (90)
11. ttl.end_fill ()
12.
13. #Hiding the turtle after completing the drawing
14. ttl. hide turtle ()
15. turtle. Done ()
output: -
date -
9|Page
PROGRAM-09
Aim: -
Program: -
1. # Define a class
2. class student:
3. # Define an attribute
4. student_Rollno = 0
10 | P a g e
16. # Access attributes using student3
17. student3.studentRollno = 1012
18. print (f"varsha Rollno: {student3.studentRollno}")
19. # Access attributes using student4
20. student4.studentRollno = 1024
21. print (f"kajal Rollno: {student4.studentRollno}")
output: -
date -
11 | P a g e
PROGRAM-10
Aim: -
A) Using a numpy module create an array and check the
following:
1. Type of array
2. Axes of array
3. Shape of array
4. Type of elements in array
Program: -
import numpy as np
arr=np. array ([[1,2,3,4],[4,2,5,3]])
print ("Array is of type:”, type(arr))
print ("no. of dimensions: “arr. ndim)
print ("Shape of array: “arr. shape)
print ("Size of array:”, arr. size)
print ("Array stores elements of type:"), arr. dtype
output: -
date -
12 | P a g e