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

PG Python (5 Students)

The document is a practical record for students at Bharathi Women’s Arts and Science College, specifically for the Computer Science and Application department. It includes a certificate of authenticity, a list of practical programs covering various Python programming concepts such as data structures, control flow, and functions. The document also contains sample code and outputs for each program demonstrating the implementation of these concepts.

Uploaded by

nithiyapriya
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 views45 pages

PG Python (5 Students)

The document is a practical record for students at Bharathi Women’s Arts and Science College, specifically for the Computer Science and Application department. It includes a certificate of authenticity, a list of practical programs covering various Python programming concepts such as data structures, control flow, and functions. The document also contains sample code and outputs for each program demonstrating the implementation of these concepts.

Uploaded by

nithiyapriya
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

BHARATHI WOMEN’S ARTS AND SCIENCE COLLEGE

(AN ISO 9001-2000 CERTIFIED INSTITUTION)

THATCHUR, KALLAKURICHI-606213.

DEPARTMENT OF COMPUTER SCIENCE &


APPLICATION

NAME : …………………………………………………………………………………………

COURSE : …………………………………………………………………………………………

REGISTER NO : …………………………………………………………………………………………
BHARATHI WOMEN’S ARTS AND SCIENCE COLLEGE
(AN ISO 9001-2000 CERTIFIED INSTITUTION)

THATCHUR, KALLAKURICHI-606213.

DEPARTMENT OF COMPUTER SCIENCE & APPLICATION

CERTIFICATE

Certificate that this is the bonafide record of practical done by …………………………….

………………………………. Register Number …………………………………. year/Branch

…………………In the lab ……………………………………………………………During the

academic year………………………

Faculty Incharge Head of the Department

Submitted for the University Practical Examination held on……………………

Internal Examiner External Examiner


SUBJECT CODE: 23PCSCP13 SUBJECT NAME: ALGORITHM AND PYTHON LAB

SNO DATE CONTENT PAGE NO SIGN

01 Programs using elementary data items,


lists, dictionaries and tuples

02 Programs using conditional branches,

03 Programs using loops.

04 Programs using functions

05 Programs using exception handling

06 Programs using inheritance

07 Programs using polymorphism

08 Programs to implement file operations.

09 Programs using modules

10 Programs for creating dynamic and


interactive webpages using forms.
#PROGRAM: 1 PROGRAM USING ELEMENTARY DATA ITEMS, LISTS,
DICTIONARIES AND TUPLES

#Demonstrating List Operations


#Creating a List
print("#####################################")
print(" DEMONSTRATING LIST OPERATIONS ")
print("#####################################")
list1=[]
print("Blank list:")
print(type(list1))

#creating a list of number


list=[10,20,30,40,50,60]
print("\nList of number:")
print(list)
print("Accessing a element from the list:")
print(list[0])
print(list[3])
#calculating the len()
print("The length of the list and list1:")
print(len(list))
print(len(list1))
#adding of tht element inthe list
[Link](70)
[Link](80)
print("\nAfter addition of three number:")
print(list)

#addition of element at specific position(using insert method)


[Link](0,'computer science')
print("\nList after insert operation:")
print(list)
#reverse a list
print("Reverse List:")
[Link]()
print(list)
#removing element for a list
[Link](30)
[Link](60)
print("\nList after removal of two element:")
print(list)
OUTPUT:
#####################################
DEMONSTRATING LIST OPERATIONS
#####################################
Blank list:
<class 'list'>
List of number:
[10, 20, 30, 40, 50, 60]
Accessing a element from the list:
10
40
The length of the list and list1:
6
0

After addition of three number:


[10, 20, 30, 40, 50, 60, 70, 80]

List after insert operation:


['computer science', 10, 20, 30, 40, 50, 60, 70, 80]
Reverse List:
[80, 70, 60, 50, 40, 30, 20, 10, 'computer science']

List after removal of two element:


[80, 70, 50, 40, 20, 10, 'computer science']
#DEMONSTRATING DICTIONARY OPERATIONS

#Creating a dictionary
print("*********************************")
print(" IMPLEMENTATION OF DICTIONARY ")
print("*********************************")

#Creating an Empty Dictionary


dict={}
print("Empty Dictionary: ")
print(dict)

#creating a dictionary
employee={"Name": "Roja","Age": 22,"Salary": 25000,"Company":
"GOOGLE"}
print(type(employee))
print("Printing employee data..")
print(employee)

#To display
print("Name: %s"%employee["Name"])
print("Age: %d"%employee["Age"])
print("Salary; %d"%employee["Salary"])
print("Company: %s"%employee["Company"])

#Get employee details from the user


print("Enter the details of the new employee...")
employee["Name"]=input("name: ")
employee["Age"]=int(input("age: "))
employee["Salary"]=int(input("salary: "))
employee["Company"]=input("company: ")
print("Printing the new data")
print(employee)

#DELETING name and company from the employee data


del employee["Name"]
del employee["Company"]
print("Printing the modified information")
print(employee)

#Deleting dictionary(employee)
print("Deleting the dictionary:", employee)
del employee
print("Lets try to print it again")
print(employee)
#Name employee is not defined
OUTPUT:
**************************************
IMPLEMENTATION OF DICTIONARY
**************************************
Empty Dictionary: {}
<class 'dict'>
Printing employee data..
{'Name': 'Roja', 'Age': 22, 'Salary': 25000, 'Company': 'GOOGLE'}
Name: Roja
Age: 22
Salary; 25000
Company: GOOGLE
Enter the details of the new employee...
name: MINI
age: 26
salary: 50000
company: IBM
Printing the new data:{'Name': 'MINI', 'Age': 26, 'Salary': 50000, 'Company': 'IBM'}
Printing the modified information: {'Age': 26, 'Salary': 50000}
Deleting the dictionary: {'Age': 26, 'Salary': 50000}
Lets try to print it again
Traceback (most recent call last):
File "E:\pRIYA\Roja 1 pg cs\[Link]", line 45, in <module>
print(employee)
NameError: name 'employee' is not defined
#PYTHON PROGRAM TO DICTIONARY BUILT-IN-FUNCTIONS

print(" IMPLEMENTATION OF DICTIONARY ")


print("*********************************")
#DICTIONARY BUILT IN FUNCTIONS
squares={0:0,1:1,3:9,5:25,7:49,9:81}
print(all(squares))
print(any(squares))
print(len(squares))
print(sorted(squares))
for i in squares:
print(squares[i])
print([Link]())
print(squares)

print([Link]())
print(squares)
#remove all items

[Link]()
print(squares)

#delete the dictionary itself


del squares
#throws error
print(squares)
OUTPUT:
IMPLEMENTATION OF DICTIONARY
***************************************
False
True
6
[0, 1, 3, 5, 7, 9]
0
1
9
25
49
81
(9, 81)
{0: 0, 1: 1, 3: 9, 5: 25, 7: 49}
(7, 49)
{0: 0, 1: 1, 3: 9, 5: 25}
{}
Traceback (most recent call last):
File "E:\pRIYA\Roja 1 pg cs\[Link]", line 29, in <module>
print(squares)
NameError: name 'squares' is not defined
#CREATING TUPLES, NESTED TUPLES, REPEATING TUPLES
ELEMENTS

print("*************************")
print(" Working With Tuples ")
print("*************************")

#Creating an empty tuple


empty_tuple=0
print("Empty tuple :",empty_tuple);

#Creating tuple having integers


int_tuple=(4,6,8,10,12,3)
print("Tuple with integer :",int_tuple)

#Creating a tuple having objects of different data types


mixed_tuple=(2,"roja",2.0)
print("Tuple having mixed data types :",mixed_tuple)

#Creating a nested tuples


nested_tuple=("roja",{1,2,3,4},[2,3])
print("Nested tuples :",nested_tuple)

#To shaw repetition in tuples


tuple_1=('python',"tuple")
print("Original tuple :",tuple_1)

#Repeating the tuple elements


tuple_1=tuple_1*3
print("New tuple is :",tuple_1)
#To show how to concatenate tuples reating a tuple
tuple_2=("Python","tuple","ordered","immutable")

#Adding a tuple to the tuple


print("Adding a tuple to the tuples :")
print(tuple_2+(4,5,6))
OUTPUT:
*************************
Working with Tuples
*************************
Empty tuple :0
Tuple with integer : (4, 6, 8, 10, 12, 3)
Tuple having mixed data types : (2, 'roja', 2.0)
Nested tuples : ('roja', {1, 2, 3, 4}, [2, 3])
Original tuple : ('python', 'tuple')
New tuple is : ('python', 'tuple', 'python', 'tuple', 'python',
'tuple')
Adding a tuple to the tuples :('Python', 'tuple', 'ordered', 'immutable', 4, 5, 6)
#Python program to perform concatenation of two string tuples

print(" Working With Tuples(concatenation of string) " )


print(" *********************************************")

import operator
# Intialing and printing tupels
strTup1=("python","learn","web");
strTup2=("programming","coding","developement")
print("The elements of tuples 1 :"+str(strTup1))
print("The elements of tuples 2 :"+str(strTup2))

#Performing concotenation of string tuples


concTup=tuple(map([Link],strTup1,strTup2))
print("The tuple with concotenated string :"+str(concTup))

#Python program tofind the sum pf the tuples of integer values


#Creating and printing the tuples of integer values
myTuple=(2,3,4,5,5)
#Printing original tuple
print("The original tuple is :"+str(myTuple))
#Finding sum of all tuple elements
tupSum=sum(list(myTuple))

#Printing the tuples sum


print("The summation of tuple elements are :"+str(tupSum))
OUTPUT:
Working With Tuples(concotenation of string)
************************************************
The elements of tuples 1 :('python', 'learn', 'web')
The elements of tuples 2 :('programming', 'coding', 'developement')
The tuple with concotenated string :('pythonprogramming', 'learncoding',
'webdevelopement')
The original tuple is :(2, 3, 4, 5, 5)
The summation of tuple elements are :19
#PROGRAM: 2 PROGRAM USING CONDITIONAL BRANCHES

#PYTHON PROGRAM TO CHECK IF YEAR IS A LEAP YEAR OR NOT


print("*********************************")
print("FLOW CONTROL(USING [Link])")
print("*********************************")

year=2000
#to get year(integer input)from the user
#year=int(input("entet a year:")
#divided buy 100 means century year(ending with 00)
#century year divided by 400 is leap year

if(year%400==0)and(year%100==0):
print("{0} is a leap year".format(year))

#not divided by 100 means not a century year


#yera divided by 4 is a leap year

elif(year%4==0)and(year%100!=0):
print("{0} is a leap year".format(year))

#if not divided by both 4009century year)and 4(not century year)


#year is not leap year
else:
print("{0} is not a leap year".format(year))
OUTPUT:
*********************************
FLOW CONTROL (USING [Link])
*********************************
2000 is a leap year

*********************************
FLOW CONTROL (USING [Link])
*********************************
2001 is not a leap year
#PYTHON PROGRAM TO CHECK THE PRIME NUMBER IN BETWEEN
900 TO 1000

print("FLOW CONTROL(USING IF-ELSE ")


print("***************************")
lower=900
upper=1000
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower,upper+1):
if num>1:
for i in range(2,num):
if(num%i)==0:
break
else:
print(num)

OUTPUT:

FLOW CONTROL (USING IF-ELSE


**************************

Prime numbers between 900 and 1000 are:


907
911
919
929
937
941
947
953
967
971
977
983
991
997
#PROGRAM: 3 PROGRAM USING LOOP (USING FOR LOOP)

print("FLOW CONTROL(USING FOR)")


print("******************************")
num=int(input("Enter the number of which the user wants to print the
multiplication table:"))
print("The multiplication table of:",num)
for i in range(1,11):
print(num,'x',i,'=',num*i)

OUTPUT:
FLOW CONTROL (USING FOR)
*************************
Enter the number of which the user wants to print the multiplication table: 5
The multiplication table of: 5
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
#PROGRAM USING LOOP (USING WHILE LOOP)

print("FLOW CONTROL(USING WHILE"))


print("********************************")
number=int(input("Enter the number of which the user wants to print the
multiplication table:"))
count=1
print("The multiplication table of:",number)
while count<=10:
number=number*1
print(number,'x',count,'=',number*count)
count+=1

OUTPUT:
FLOW CONTROL (USING WHILE)
*********************************
Enter the number of which the user wants to print the multiplication table: 5
The multiplication table of: 5
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
#PROGRAM: 4 PROGRAM USING FUNCTION
print("SIMPLE CALCULATOR USING FUNCTION")
print("*****************************************")
def add(p,q):
return p+q
def subtract(p,q):
return p-q
def multiply(p,q):
return p*q
def divide(p,q):
return p/q
num_1=int(input("Please Enter the First number:"))
num_2=int(input("Please Enter the Second number:"))
print("Please select the operation:")
print("a,add")
print("[Link]")
print("[Link]")
print("[Link]")
choice=input("Please enter choice(a/b/c/d):")
if choice=='a':
print(num_1,"+",num_2,"=",add(num_1,num_2))
elif choice==’b’:
print(num_1,"-",num_2,"=",subtract(num_1,num_2))
elif choice=='c':
print(num_1,"*",num_2,"=",multiply(num_1,num_2))
elif choice=='d':
print(num_1,"/",num_2,"=",divide(num_1,num_2))
else:
print("This is an invalid input")
OUTPUT:
SIMPLE CALCULATOR USINH FUNCTION
*****************************************
Please Enter the First number:30
Please Enter the Second number:20
Please select the operation:
a,add
[Link]
[Link]
[Link]
Please enter choice(a/b/c/d):c
30 * 20 = 600

SIMPLE CALCULATOR USINH FUNCTION


*****************************************
Please Enter the First number:100
Please Enter the Second number:200
Please select the operation:
a,add
[Link]
[Link]
[Link]
Please enter choice(a/b/c/d):a
100 + 200 = 300
#Program using function

print("HCF function")
print("**************")
def calculate_hcf(x,y):
if x>y:
smaller=y
else:
smaller=x
for i in range(1,smaller+1):
if((x%i==0)and(y%i==0)):
hcf=i
return hcf
num1=int(input("Enter first number:"))
num2=int(input("Enter second number:"))
print("The H.C.F of",num1,"and",num2,"is",calculate_hcf(num1,num2))

OUTPUT:
HCF function
*************
Enter first number:9
Enter second number:81
The H.C.F of 9 and 81 is 9
HCF function
*************
Enter first number:50
Enter second number:75
The H.C.F of 50 and 75 is 25
#PROGRAM : 5 PROGRAMS USING EXCEPTION HANDLING
print("EXCEPTION HANDLING")
print("***************************")
print("Practicing for try block")
try:
numerator=50
denom=int(input("Enter the denonminator="))
quotient=(numerator/denom)
print("Division performed successfully")
except ZeroDivisionError:
print("Denonminator as zero is not allowed")
else:
print("The result of division operation is",quotient)
finally:
print("OVER AND OUT")
print("Handling exception using try ...except...else...finally")
try:
numerator=50
denom=int(input("\n\nEnter the denominator="))
quotient=(numerator/denom)
print("Division performed successfully")
except ZeroDivisionError:
print("Denominator as ZERO is not alloewd")
except ValueError:
print("Only INTEGERS should be entered")
else:
print("The result of division operation is",quotient)
finally:
print("OVER AND OUT")
OUTPUT:1
print("EXCEPTION HANDLING")
print("***************************")
Practicing for try block
Enter the denonminator=0
Denonminator as zero is not allowed
OVER AND OUT
Handling exception using try ...except...else...finally
Enter the denominator=10
Division performed successfully
The result of division operation is 5.0
OVER AND OUT

OUTPUT: 2
print("EXCEPTION HANDLING")
print("***************************")
Practicing for try block
Enter the denonminator=10
Division performed successfully
The result of division operation is 5.0
OVER AND OUT
Handling exception using try ...except...else...finally
Enter the denominator=a
Only INTEGERS should be entered
OVER AND OUT
#PROGRAM: 6 Programs using inheritance

class BankAccount:
def __init__(self,account_number,date_of_opening,balance,customer_name):
self.account_number=account_number
self.date_of_opening=date_of_opening
[Link]=balance
self.customer_name=customer_name

def deposit(self,amount):
[Link]+=amount
print(f"{amount}has been deposited in your account")

def withdraw(self,amount):
if amount>[Link]:
print("insufficient balance")
else:
[Link]-=amount
print(f"{amount}has been withdraw from your account")

def check_balance(self):
print(f"current balance is {[Link]}.")

def print_customer_details(self):
print("Name:",self.customer_name)
print("Account number:",self.account_number)
print("Date of opening:",self.date_of_opening)
print(f"Balance:{[Link]}\n")

#input customer details


ac_no_1=BankAccount(2345,"01-10-2011",1000,"Roja")
ac_no_2=BankAccount(3345,"09-01-2013",8000,"Priya")
ac_no_3=BankAccount(1345,"13-03-2001",7000,"Shyam")
ac_no_4=BankAccount(2145,"22-09-2010",5000,"Mini")
ac_no_5=BankAccount(1445,"15-12-2000",10000,"Deepika")
print("=========================================")
print(" BANK MANAGEMENT SYSTEM USING INHERITANCE ")
print("=========================================")
print("Customer Details:")
ac_no_1.print_customer_details()
ac_no_2.print_customer_details()
ac_no_3.print_customer_details()
ac_no_4.print_customer_details()
ac_no_5.print_customer_details()
print("============================")
print("Details of account number 4")
print("============================")
ac_no_4.print_customer_details()
print("============================")
print("Rs 1000 has been deposited in account number 4\n")
ac_no_4.deposit(1000)
print("Check balance of account number 4\n")
ac_no_4.check_balance()
print("The customer withdrawal 3000\n")
ac_no_4.withdraw(3000)
print("The customer withdrawal 6000\n")
ac_no_4.withdraw(6000)
print("Customer check the balance\n")
ac_no_4.check_balance()
OUTPUT:
==========================================
BANK MANAGEMENT SYSTEM USING INHERITANCE
==========================================
Customer Details:
Name: Roja
Account number: 2345
Date of opening: 01-10-2011
Balance:1000

Name: Priya
Account number: 3345
Date of opening: 09-01-2013
Balance:8000

Name: Shyam
Account number: 1345
Date of opening: 13-03-2001
Balance:7000

Name: Mini
Account number: 2145
Date of opening: 22-09-2010
Balance:5000

Name: Deepika
Account number: 1445
Date of opening: 15-12-2000
Balance:10000

============================
Details of account number 4
============================
Name: Mini
Account number: 2145
Date of opening: 22-09-2010
Balance:5000
============================
Rs 1000 has been deposited in account number 4

1000has been deposited in your account


Check balance of account number 4

current balance is 6000.


The customer withdrawal 3000

3000has been withdraw from your account


The customer withdrawal 6000
#Program : 7 Programs using polymorphism

class Square:
def __init__(self,side_length):
self.side_length=side_length

def area(self):
return self.side_length**2

class Circle:
def __init__(self,radius):
[Link]=radius

def area(self):
import math
return [Link]*[Link]**2

def calculate_area(shape):
return [Link]()

square=Square(4)
circle=Circle(3)
print("POLYMORPHISM")
print("============")
print("Area of Square:",calculate_area(square))
print("Area of Circle:",calculate_area(circle))
OUTPUT:
POLYMORPHISM
=============

Area of Square: 16
Area of Circle: 28.274333882308138
#PROGRAM: 8 PROGRAMS USING FILE OPERATIONS.

#Open ,Close, Read, Write and Append the file mode using File Handling
#[Link] the file [Link] in read mode

print("======================================")
print(" Programs to implement file operations. ")
print("======================================")

fileptr=open("[Link]","r")
if fileptr:
print("\nFile is opened successfully")

#[Link] [Link] using with statement


with open("[Link]",'r')as f:
content=[Link]()
print("\nThe Content of the [Link]:")
print(content)

#[Link] the [Link] in append [Link] a new file if no such file exists
fileptr=open("[Link]","w")

#[Link] the content to the file


[Link]('''Python is a high-level, general-purpose and very popular programming
language.''')

#[Link] the opened the file


#[Link]()

#[Link] the [Link] in write mode


fileptr=open("[Link]","a")
#[Link] the content of the file
[Link]("It was created by Guido van Rossum in 1991")

#[Link] tne file,txt in read [Link] an error if no such file exists


fileptr=open("[Link]","r")

print("\nThe Content of the [Link]:")


#[Link] a for loop
for i in fileptr:
print(i)

#i contains each line of the file


#[Link] the opened file
[Link]()
OUTPUT:
======================================
Programs to implement file operations
======================================

File is opened successfully

The Content of the [Link]:


Python is a popular programming language,

The Content of the [Link]:


Python is a high-level, general-purpose and very popular programming [Link]
was created by Guido van Rossum in 1991
#Program: 9 Programs using modules

#math() and sys() function


#python program to show how to import a standard module
#we will import the math module which is a standard module

print("BUILT IN MODULES")
print("================")
import math
print("\nThe value of Euler's Number is",math.e)

#we will import the math module and give a different name to it

import math as mt
print("\nThe value of Euler's Number is",mt.e)

#we will import euler's number from the math module uysing the from keyboard

from math import e


print("\nThe value of Euler's Number us",e)

#python program to show how to import multiple objects form a module

from math import e,tau


print("\nThe value of Tau Constant is:",tau)
print("\nThe value of The Euler's Number is:",e)

#importing the complete math module using*

from math import*


#accessing functions of math module witjout using the dot operator

print("\nCalculating Square Root:",sqrt(25))


print("\nCalculating Tanget of an Angle:",tan(pi/6))

#here pi is also imported from the math moudle


#we will import the sys module

import sys

#we will import sys path

print("\nList of System:\n")
print([Link])

#pyhton program to prime the directly of a module

print("\nList of Functions:\n",dir(str),end=",")
OUTPUT:
BUILT IN MODULES
================
The value of Euler's Number is 2.718281828459045
The value of Euler's Number is 2.718281828459045
The value of Euler's Number us 2.718281828459045
The value of Tau Constant is: 6.283185307179586
The value of The Euler's Number is: 2.718281828459045
Calculating Square Root: 5.0
Calculating Tanget of an Angle: 0.5773502691896257
List of System:
['E:\\NISHA\\Roja 1 pg cs', 'C:\\Program Files\\Python311\\Lib\\idlelib',
'C:\\Program Files\\Python311\\[Link]', 'C:\\Program
Files\\Python311\\Lib', 'C:\\Program Files\\Python311\\DLLs',
'C:\\Users\\Admin.SYS116\\AppData\\Roaming\\Python\\Python311\\site-
packages', 'C:\\Program Files\\Python311', 'C:\\Program
Files\\Python311\\Lib\\site-packages']
List of Functions:
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__getstate__', '__gt__', '__hash__', '__init__',
'__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__',
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith',
'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii',
'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle',
'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix',
'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split',
'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'],
#PROGRAM USING MODULES

print("BUILT IN MODULES(Data and Time)")


print("===========================")

#date and time

import time

#prints the number of ticks spent since 12AM,1 st january 1970


print("Prints the number of ticks spent since 12AM,1 st january 1970:")
print([Link]())

import time
#returns a time tuple
print("\nThe Time structure=")
print([Link]([Link]()))

import time
#returns the formatted time
print("\nThe formatted time=")
print([Link]([Link]([Link]())))

import time
for i in range(0,5):
print(i)

#each element will be printed after 1 second


[Link](1)

#datetime module
import datetime
#returns the current datetime object
print("\nThe current datatime=")
print([Link]())

import calendar
cal=[Link](2023,10)
#printing the calendar of oct 2023 print(cal)
print("\nPrint the Calender of Oct 2023::")
print(cal)

import calendar
#printing the calendar of year 2023
print("CALENDER 2023")
s=[Link](2023)
OUTPUT:
BUILT IN MODULES (Data and Time)
============================
Prints the number of ticks spent since 12AM,1 st january 1970:
1700460084.9566157
The Time structure=
time.struct_time(tm_year=2023, tm_mon=11, tm_mday=20, tm_hour=11,
tm_min=31, tm_sec=24, tm_wday=0, tm_yday=324, tm_isdst=0)
The formatted time=
Mon Nov 20 11:31:24 2023
0
1
2
3
4
The current datatime=
2023-11-20 11:31:26.006797
Print the Calender of Oct 2023::
October 2023
Mo Tu We Th Fr Sa Su
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

CALENDER 2023
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 1 2 3 4 5 1 2 3 4 5
2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12
9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19
16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26
23 24 25 26 27 28 29 27 28 27 28 29 30 31
30 31
April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 1 2 3 4 5 6 7 1 2 3 4
3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
10 11 2 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 1 2 3 4 5 6 1 2 3
3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
31
October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 1 2 3 4 5 1 2 3
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
30 31
#PROGRAM: 10 PROGRAMS FOR CREATING DYNAMIC AND
INTERACTIVE WEBPAGES USING FORMS.

#Create a Python script, for example,[Link] with the following code:

from flask import Flask, render_template, request

app = Flask(__name__)

@[Link]('/', methods=['GET', 'POST'])


def index():
if [Link] == 'POST':
name = [Link]['name']
greeting = f"Hello, {name}!"
return render_template('[Link]', greeting=greeting)
return render_template('[Link]', greeting=None)

if __name__ == '__main__':
[Link](debug=True,port=5001)

Create a folder named templates in the same directory as your [Link]. Inside the
templates folder, create an HTML file named [Link] with the following code:

<!DOCTYPE html>
<html>
<head>
<title>Dynamic Greeting Page</title>
</head>
<body>
<h1>Dynamic Greeting Page</h1>
<form method="POST">
<label for="name">Enter your name:</label>
<input type="text" name="name" id="name">
<input type="submit" value="Submit">
</form>
<p>{{ greeting }}</p>
</body>
</html>
Output:

You might also like