0% found this document useful (0 votes)
7 views4 pages

Advanced Python Practical File

The document contains a practical file with 15 Python programs covering various concepts such as student management, file handling, exception handling, classes, inheritance, polymorphism, database connectivity, and more. Each program demonstrates a specific functionality, including a basic calculator, password generator, and email validation. The examples are designed to help users understand and apply Python programming techniques effectively.

Uploaded by

hd330117
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)
7 views4 pages

Advanced Python Practical File

The document contains a practical file with 15 Python programs covering various concepts such as student management, file handling, exception handling, classes, inheritance, polymorphism, database connectivity, and more. Each program demonstrates a specific functionality, including a basic calculator, password generator, and email validation. The examples are designed to help users understand and apply Python programming techniques effectively.

Uploaded by

hd330117
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

ADVANCED PYTHON PRACTICAL FILE

Program 1: Student Management System (Using Dictionary)

students = {}

def add_student():
roll = input("Enter Roll No: ")
name = input("Enter Name: ")
marks = float(input("Enter Marks: "))
students[roll] = {"Name": name, "Marks": marks}

def display_students():
for roll, data in [Link]():
print(roll, data)

while True:
print("[Link] [Link] [Link]")
ch = input("Enter choice: ")
if ch == '1':
add_student()
elif ch == '2':
display_students()
else:
break

Program 2: File Handling (Write and Read File)

f = open("[Link]", "w")
[Link]("Hello, this is file handling example.")
[Link]()

f = open("[Link]", "r")
print([Link]())
[Link]()

Program 3: Exception Handling Example

try:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Division:", a/b)
except ZeroDivisionError:
print("Cannot divide by zero")
except ValueError:
print("Invalid input")

Program 4: Class and Object Example

class Person:
def __init__(self, name, age):
[Link] = name
[Link] = age

def display(self):
print("Name:", [Link])
print("Age:", [Link])

p1 = Person("Rahul", 20)
[Link]()

Program 5: Inheritance Example

class Animal:
def speak(self):
print("Animal speaks")

class Dog(Animal):
def bark(self):
print("Dog barks")

d = Dog()
[Link]()
[Link]()

Program 6: Polymorphism Example

class Bird:
def sound(self):
print("Bird sound")

class Sparrow(Bird):
def sound(self):
print("Chirp Chirp")

b = Sparrow()
[Link]()

Program 7: Lambda Function and Map

numbers = [1, 2, 3, 4, 5]
squares = list(map(lambda x: x*x, numbers))
print("Squares:", squares)

Program 8: List Comprehension

numbers = [1,2,3,4,5,6]
even = [x for x in numbers if x % 2 == 0]
print("Even numbers:", even)

Program 9: Database Connectivity (SQLite)


import sqlite3
conn = [Link]("[Link]")
cursor = [Link]()
[Link]("CREATE TABLE IF NOT EXISTS student(id INTEGER, name TEXT)")
[Link]("INSERT INTO student VALUES(1,'Amit')")
[Link]()
[Link]("SELECT * FROM student")
print([Link]())
[Link]()

Program 10: Basic Calculator Using Functions

def add(a,b): return a+b


def sub(a,b): return a-b
def mul(a,b): return a*b
def div(a,b): return a/b

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


b = float(input("Enter second number: "))
print("Add:", add(a,b))
print("Sub:", sub(a,b))
print("Mul:", mul(a,b))
print("Div:", div(a,b))

Program 11: Password Generator

import random
import string

length = 8
chars = string.ascii_letters + [Link]
password = ''.join([Link](chars) for i in range(length))
print("Generated Password:", password)

Program 12: Guess the Number Game

import random
number = [Link](1,10)

while True:
guess = int(input("Guess number (1-10): "))
if guess == number:
print("Correct!")
break
else:
print("Try Again")

Program 13: Email Validation

import re
email = input("Enter email: ")
pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$'
if [Link](pattern, email):
print("Valid Email")
else:
print("Invalid Email")

Program 14: Palindrome String Using Function

def is_palindrome(s):
return s == s[::-1]

text = input("Enter string: ")


if is_palindrome(text):
print("Palindrome")
else:
print("Not Palindrome")

Program 15: Count Words in File

with open("[Link]", "r") as f:


text = [Link]()
words = [Link]()
print("Total words:", len(words))

You might also like