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

Python Record

The document provides a comprehensive guide for installing Python and configuring the interpreter and IDEs like Jupyter and Google Colab. It includes step-by-step instructions for installation, setting the PATH, and executing various Python programs that cover fundamental programming concepts such as data types, control structures, and functions. Additionally, it contains sample code for tasks like finding the largest number, calculating simple interest, and manipulating strings and lists.

Uploaded by

vnrexamresources
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 views31 pages

Python Record

The document provides a comprehensive guide for installing Python and configuring the interpreter and IDEs like Jupyter and Google Colab. It includes step-by-step instructions for installation, setting the PATH, and executing various Python programs that cover fundamental programming concepts such as data types, control structures, and functions. Additionally, it contains sample code for tasks like finding the largest number, calculating simple interest, and manipulating strings and lists.

Uploaded by

vnrexamresources
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

DEPARTMENT OF CSE(CYS, DS) And AI &

DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Install Python and configure Interpreter & IDE like Jupyter, google colab.

 Go to [Link] under download tab choose the OS(windows) and click on the
current version to get downloaded.
 Executable file will be downloaded.

 Open the executable file you will get a setup


 Check the boxes and click on the customize installation

1 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

 Check the boxes, click on next

 Check the boxes, choose the install location and click on install
 nstallation starts

2 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

 Installation was done, click on close


To verify python is installed/not
 After installation, open Command Prompt and type:
 python --version
 If it shows a version number, Python is ready.
PATH Configuration
 PATH allows Python to run from any folder
 Add Python folder to system variables
 Required for command prompt execution
 To set the PATH click on search and enter environment variables click on edit
the system environment variables

3 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

 Click on environment variables

 Click on path and click on edit

4 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

 Click on new and paste the path where the python was installed

 Click on OK

5 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write and execute your first Python program to display "Hello, Python!".
SOURCE CODE:
print("Hello, python!")
Output:

6 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Use command-line arguments to run Python scripts.


SOURCE CODE:
import sys
a=int([Link][1])
b=int([Link][2])
print(a+b)
OUTPUT:

8 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to find the largest element among three Numbers.


Program:
a,b,c=input("Enter three numbers:").split()
if int(a)>int(b)and int(a)>int(c):
print("Largest element:",a)
elif int(b)>int(a)and int(b)>int(c):
print("Largest element:",b)
else:
print("Largest element:",c)
Output:

9 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to print the sum of all the even numbers in the range 1 - 50 and
print the even sum.
SOURCE CODE:
sum=0
for i in range (2,51,2):
print(i)
sum+=i
print("Sum of even numbers in 1-50:",sum)
Output:

10 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a Program to display all prime numbers within an interval of given X1 & X2.
SOURCE CODE:
x1,x2=input("Enter range:").split("-")
for i in range (int(x1),int(x2)+1,1):
s=int(i**(1/2))
count=0
for j in range (1,s+1,1):
if(i%j==0):
count+=1
if(count==1):
print(i)
OUTPUT:

11 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Program to demonstrate Python’s built-in data types.


SOURCE CODE:
a=10
print("Type of",a,":",type(a))
s="Python"
print("Type of",s,":",type(s))
pi=3.14
print("Type of",pi,":",type(pi))
b=21>5
print("Type of",b,":",type(b))

OUTPUT:

12 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Type conversion using int(), float(), str(), etc.


SOURCE CODE:
a=12.4
print(type(a))
b=str(a)
print(type(b))
c=int(a)
print(type(c))
OUTPUT:

13 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Calculate Simple Interest and Area of a Circle.


Simple interest:
SOURCE CODE:
p=int(input("Enter principal amount:"))
t=float(input("Enter time period(in years):"))
r=float(input("Enter rate of interest:"))
s=(p*t*r)/100
print("Simple interest:",s)
OUTPUT:

Area of a circle:
SOURCE CODE:
r=float(input("Enter radius of circle:"))
a=3.14*(r**2)
print("Area of circle:",a)
OUTPUT:

14 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Program to swap two numbers without using a third variable.


SOURCE CODE:
a,b=input("Enter two numbers:").split(",")
c=int(a)
d=int(b)
print("Before swapping:\na =",c,"b =",d)
c=c+d
d=c-d
c=c-d
print("After swapping:\na =",c,"b =",d)
OUTPUT:

15 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to print the following patterns using loop:


*
**
***
****
SOURCE CODE:
row=int(input("Enter number of rows:"))
for i in range (row+1):
print("*"*i)
OUTPUT:

16 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to print multiplication table of a given number X1 to range X2.


SOURCE CODE:
n,x1,x2=(input("Enter number and range(low-high) respectively:").split())
for i in range(int(x1),int(x2)+1,1):
print(f"{n}*{i}={int(n)*i}")
OUTPUT:

17 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Grade calculation using if-elif-else.


SOURCE CODE:
marks=int(input("Enter marks:"))
if marks>=90:
print("Grade:O")
elif marks<90 and marks>=75:
print("Grade:A")
elif marks<75 and marks>45:
print("Grade:B")
else:
print("Fail")
OUTPUT:

18 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Determine the type of a triangle (equilateral, isosceles, scalene).


SOURCE CODE:
a,b,c=input("Enter three sides of a triangle:").split()
a=int(a)
b=int(b)
c=int(c)
if b+c>a and a+c>b and a+b>c:
if(a==b and a==c and b==c):
print("Equilateral triangle")
elif a!=b and b!=c and c!=a:
print("Scalene triangle")
elif a>b or a>c or b>a or b>c or c>a or c>b:
print("Isosceles triangle")
else:
print("NOT a triangle")
OUTPUT:

19 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to find the length of the string without using any library functions.
SOURCE CODE:
s=input("Enter a string:")
count=0
for i in s:
count+=1
print("Length of string:",count)
OUTPUT:

20 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to check if two strings are anagrams or not.


SOURCE CODE:
s1,s2=input("Enter two strings:").split(",")
l1=[]
l2=[]
if(len(s1)==len(s2)):
for i in [Link]():
[Link](i)
[Link]()
for j in [Link]():
[Link](j)
[Link]()
if l1==l2:
print("Anagram")
else:
print("NOT an anagram")
else:
print("NOT an anagram")

OUTPUT:

21 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to check if the substring is present in a given string or not.


SOURCE CODE:
s1,s2=input("Enter string 1 and string 2 respectively:").split(",")
if [Link]() in [Link]():
print(f"{s2} is substring")
else:
print(f"{s2} is NOT substring")
OUTPUT:

22 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to perform the given operations on a list:


i. add ii. insert iii. slicing
SOURCE CODE:
l=[21,43,13,54]
print("Original list:",l)
[Link](56)
print("List after appending 56:",l)
[Link](1,76)
print("List after inserting 76 at index 1:",l)
print("List slicing:",l[1:3])

OUTPUT:

23 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to perform any 5 built-in functions by taking any list.


SOURCE CODE:
l=[12,87,"sara",54.2]
print("Original list:",l)
[Link](42)
print(l)
[Link](2,62)#index,value
print(l)
[Link]()
print(l)
[Link]
e(87)#takes value as parameter
print(l)
[Link](1)#takes index as parameter
print(l)

OUTPUT:

24 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to get a list of the even numbers from a given list of numbers.
SOURCE CODE:
l=[12,67,98,45,36,27,90]
even=[]
for i in l:
if(i%2==0):
[Link](i)
print("Even numbers from list:",even)
OUTPUT:

25 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to create tuples (name, age, address, college) for at least two
members and concatenate the tuples and print the concatenated tuples.
SOURCE CODE:
t1=("abc",21,"Mumbai","clg1")
t2=("xyz",23,"Delhi","clg2")
print(t1+t2)
OUTPUT:

26 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to return the top 'n' most frequently occurring chars and their
respective position.
SOURCE CODE:
s = input("Enter the string: ")
freq = {}
for ch in s:
if ch in freq:
freq[ch] += 1
else:
freq[ch] = 1
max_freq = max([Link]())
for ch in freq:
if freq[ch] == max_freq:
positions = []
for i in range(len(s)):
if s[i] == ch:
[Link](i)
print("Most repeated character:", ch)
print("Frequency:", max_freq)
print("Positions:", positions)
OUTPUT:

27 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program on counts. e. g. aaaaabbbbcccc, it should return ex:


[(a 5) (b 4) (c 4)]
SOURCE CODE:
s = input("Enter string:")
result = []
i=0
while i < len(s):
char = s[i]
count = 1
while i + 1 < len(s) and s[i + 1] == char:
count += 1
i += 1
[Link]((char, count))
i += 1
print(result)
OUTPUT:

28 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to count the number of vowels in a string.


SOURCE CODE:
s=input("Enter string:")
count=0
l=[]
v="aeiou"
for ch in [Link]():
for i in v:
if ch==i and ch not in l:
count+=1
[Link](ch)
print("Number of vowels in",s,count)
OUTPUT:

29 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program that displays which letters are present in both strings.
SOURCE CODE:
s1,s2=input("Enter Strings:").split()
l=[]
for i in [Link]():
for j in [Link]():
if i==j and i not in l:
[Link](i)
print("Letters present in both",s1,s2,l)
OUTPUT:

30 25071A7210
DEPARTMENT OF CSE(CYS, DS) And AI &
DS
NAME OF THE LAB: WEEK:

EXPERIMENT NO: DATE:

Write a program to sort given list of strings in the order of their vowel counts.
SOURCE CODE:
words = ["string", "character", "python", "program"]
vowels = "aeiouAEIOU"
result = []
for word in words:
count = 0
for ch in word:
if ch in vowels:
count += 1
[Link]((word, count))
sorted_result = sorted(result, key=lambda x: x[1])
print(sorted_result)s
OUTPUT:

31 25071A7210

You might also like