0% found this document useful (0 votes)
5 views11 pages

Part A & B Python Programming Lab Manual

The document contains a collection of Python programming tasks divided into two parts: Part A includes scripts for various functionalities like checking leap years, Fibonacci numbers, and password validation, while Part B focuses on more advanced tasks such as removing duplicates from lists, creating GUIs, and using libraries like SQLite, Matplotlib, NumPy, and Pandas. Additionally, it outlines an evaluation scheme for lab examinations based on program writing, execution, and viva voce. Each task is accompanied by example code snippets demonstrating the implementation.

Uploaded by

jndka09
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)
5 views11 pages

Part A & B Python Programming Lab Manual

The document contains a collection of Python programming tasks divided into two parts: Part A includes scripts for various functionalities like checking leap years, Fibonacci numbers, and password validation, while Part B focuses on more advanced tasks such as removing duplicates from lists, creating GUIs, and using libraries like SQLite, Matplotlib, NumPy, and Pandas. Additionally, it outlines an evaluation scheme for lab examinations based on program writing, execution, and viva voce. Each task is accompanied by example code snippets demonstrating the implementation.

Uploaded by

jndka09
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

Python Programs

Part-A

1. Python script for checking the given year is leap year or not.
2. Python script to check if a number belongs to the Fibonacci Sequence
3. Python script to solve Quadratic Equations
4. Python script to display all numbers which are divisible by 7 but
are not a multiple of 5, between given range X and Y.
5. Python script to display Multiplication Tables
6. Python script to create a calculator program
7. Explore string functions
8. Implementation of python script that takes a list of words and
returns the length of the longest one.
9. Python script handle multiple errors with one except statement.
10. Python script to check whether password is valid or not.

Conditions for a valid password are:


• Should have at least one number.
• Should have at least one uppercase and one lowercase character.
• Should have at least one special symbol.
• Should be between 6 to 20 characters long.

Part-B

1. Implement Python Script to Remove Duplicates from a List


2. Implement python script to find the repeated items of a tuple.
3. Implement python script to check whether a given key already exists or
not in a dictionary.
4. Write a python script to implement method overloading.
5. Create SQLite Database and Perform Operations on Tables.
6. Create a GUI using Tkinter module.
7. Drawing Line chart and Bar chart using Matplotlib.
8. Drawing Histogram and Pie chart using Matplotlib.
9. Create Array using NumPy and Perform Operations on Array.
10. Create DataFrame from Excel sheet using Pandas and Perform Operations on
DataFrames.

Evaluation Scheme for Lab Examination:

Assessment Criteria Marks


Writing One Program from Part A 15
One Program from Part B 15
Execution Any one of the written program 05
Viva Voce based on Python Programming 05
Total 40
1. Python script for checking the given year is leap year or not.

year = int(input("Enter year: "))

if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):


print("Leap Year")
else:
print("Not a Leap Year")

2. Python script to check if a number belongs to the Fibonacci Sequence.

N = int(input("Enter a number you want to check: "))


f1 = 0
f2 = 1
f3 = 0
if (N == 0 or N == 1):
print(f “Given number {N} is Fibonacci number”)
else:
while f3 < N:
f3 = f1 + f2
f1 = f2
f2 = f3
if f3 == N:
print(f “Given number {N} is a Fibonacci Number")
else:
print(f “Given number {N} is Not a Fibonacci Number")

3. Python script to solve Quadratic Equations.

import math

a = float(input("Enter a: "))
b = float(input("Enter b: "))
c = float(input("Enter c: "))

d = b*b - 4*a*c

if d > 0:
r1 = (-b + [Link](d)) / (2*a)
r2 = (-b - [Link](d)) / (2*a)
print("Roots are Real numbers:", r1, r2)
elif d == 0:
r = -b / (2*a)
print("Root are Identical:", r)
else:
print("Roots are Imaginary numbers:",str(r1)+"+"+str(abs(r2))+"i, "
+str(r1)+"-"+str(abs(r2))+"i")

4. Python script to display all numbers which are divisible by 7 but are not a
multiple of 5, between given range X and Y.

1
x = int(input("Enter X: "))
y = int(input("Enter Y: "))

for i in range(x, y + 1):


if i % 7 == 0 and i % 5 != 0:
print(i, end=" ")

5. Python script to display Multiplication Tables

n = int(input("Enter number: "))

for i in range(1, 11):


print(f"{n} x {i} = {n*i}")

6. Python script to create a calculator program

a = float(input("Enter first number: "))


b = float(input("Enter second number: "))

print("[Link] [Link] [Link] [Link]")


ch = int(input("Enter choice: "))

if ch == 1:
print(a + b)
elif ch == 2:
print(a - b)
elif ch == 3:
print(a * b)
elif ch == 4:
print(a / b)
else:
print("Invalid choice")

7. Explore string functions

s = input("Enter string: ")

print([Link]())
print([Link]())
print([Link]())
print(len(s))
print([Link]("a", "@"))

2
8. Implementation of python script that takes a list of words and returns the
length of the longest one.

words = input("Enter words: ").split()

longest = max(words, key=len)


print("Longest word:", longest)
print("Length:", len(longest))

9. Python script handle multiple errors with one except statement.

try:
a = int(input("Enter number: "))
b = int(input("Enter number: "))
print(a / b)
except (ValueError, ZeroDivisionError):
print("Invalid input or division by zero")

10. Python script to check whether password is valid or not. Conditions for a
valid password are:
 Should have at least one number.
• Should have at least one uppercase and one
lowercase character.
• Should have at least one special symbol
• Should be between 6 to 20 characters long.

import re

pwd = input("Enter password: ")

if (6 <= len(pwd) <= 20 and


[Link]("[A-Z]", pwd) and
[Link]("[a-z]", pwd) and
[Link]("[0-9]", pwd) and
[Link]("[@#$%]", pwd)):
print("Valid Password")
else:
print("Invalid Password")

3
Part B
1. Implement Python Script to Remove Duplicates from a List

lst = list(map(int, input("Enter list: ").split()))


res = list(set(lst))
print(res)

2. Implement python script to find the repeated items of a tuple.

t = tuple(map(int, input("Enter tuple: ").split()))


rep = [x for x in t if [Link](x) > 1]
print(set(rep))

3. Implement python script to check whether a given key already exists or not in
a dictionary.

d = {"a": 1, "b": 2, "c": 3}


key = input("Enter key: ")

if key in d:
print("Key exists")
else:
print("Key not exists")

4. Write a python script to implement method overloading.

class Demo:
def add(self, a=None, b=None):
if a is not None and b is not None:
return a + b
elif a is not None:
return a
else:
return 0

d = Demo()
print([Link]())
print([Link](10))
print([Link](10, 20))

0
10
30

4
5. Create SQLite Database and Perform Operations on Tables.

import sqlite3

con = [Link]("[Link]")
cur = [Link]()

[Link]("CREATE TABLE IF NOT EXISTS student(id INTEGER, name TEXT)")


[Link]("INSERT INTO student VALUES (1, 'Ravi')")
[Link]("SELECT * FROM student")

print([Link]())
[Link]()
[Link]()

5
6. Create a GUI using Tkinter module.

from tkinter import *

root = Tk()
[Link]("Simple GUI")

Label(root, text="Hello Python").pack()


Button(root, text="Exit", command=[Link]).pack()

[Link]()

7. Drawing Line chart and Bar chart using Matplotlib.

import [Link] as plt

x = [1,2,3,4]
y = [10,20,30,40]

[Link](x, y)
[Link](x, y)
[Link]()

8. Drawing Histogram and Pie chart using Matplotlib.

6
import [Link] as plt

data = [10,20,20,30,40,40,40]

[Link](data)
[Link]()

[Link]([30,40,30], labels=["A","B","C"])
[Link]()

7
9. Create Array using NumPy and Perform Operations on Array.

import numpy as np

a = [Link]([1,2,3])
b = [Link]([4,5,6])

print(a + b)
print(a * b)
print([Link]())

[5 7 9]
[ 4 10 18]
2.0

10. Create DataFrame from Excel sheet using Pandas and Perform
Operations on DataFrames

Output:
Name Age
0 John 25
1 Smith 30
2 Alex 27
3 Raj 22
4 Ram 32

8
9

You might also like