1.
CODING:
>>> #LIST
>>> thislist=["green","red","yellow","purple"]
>>> thislist
>>> thislist[1]="indigo"
>>> thislist
>>> [Link]("voilet")
>>> thislist
>>> print(len(thislist))
>>> del thislist[2]
>>> print(thislist)
>>> # TUPLE
>>> thistuple=("one","two","three","four")
>>> thistuple
>>> print(thistuple[2])
>>> print(len(thistuple))
>>> #SET
>>> thisset=set{"apple","banana","cherry"}
>>> thisset
>>> [Link]("papaya")
>>> thisset
>>> [Link]("banana")
>>> thisset
>>> print(len(thisset))
>>> #DICTIONARY
>>> thisdict={"apple":"green","banana":"yellow","cherry":"red"}
>>> thisdict
>>> thisdict["apple"]="red"
>>> thisdict
>>> print(thisdict)
>>> print(len(thisdict))
OUTPUT:
LIST
['green', 'red', 'yellow', 'purple']
['green', 'indigo',
'yellow', 'purple']
['green', 'indigo', 'yellow', 'purple', 'voilet']
5
['green', 'indigo', 'purple', 'voilet']
TUPLE
('one', 'two', 'three', 'four')
Three
4
SET
{'cherry', 'apple', 'banana'}
{'cherry', 'apple', 'banana', 'papaya'}
{'cherry',
'apple', 'papaya'}
3
DICTIONARY
{'cherry': 'red', 'apple': 'green', 'banana': 'yellow'}
{'cherry': 'red', 'apple': 'red', 'banana': 'yellow'}
{'cherry': 'red', 'apple': 'red', 'banana': 'yellow'}
3
[Link]:
>>>name=input(“enter student name:”)
>>>tamil=float(input(“enter tamil mark:”)
>>>english=float(input(“enter english mark:”)
>>>maths=float(input(“enter maths mark:”)
>>>science=float(input(“enter science mark:”)
>>>social=float(input(“enter social mark:”)
>>>Total=tamil+english+maths+science+social
>>>avg=total/5
>>>print(“name of the student:”,name)
>>>print(“total marks:”,avg)
>>>If avg>=90:
print(“O grade”)
elif avg>=80:
print(“D+ grade”)
elif
avg>=75:
print(“D grade”)
elif avg>=70:
print(“A+ grade”)
elif avg>=60:
print(A grade”)
elif avg>=50:
print(“B+ grade”)
else:
print(“O grade”)
OUTPUT:
Enter student name: meki
Enter tamil mark:89
Enter English mark:86
Enter maths mark:96
Enter science mark:96
Enter social mark:85
Name of the student:meki
Total marks:452.0
Average:90.4
O grade
[Link]:
(a)Factorial using for loop
>>> num=int(input("enter a number:"))
enter a number:6
>>> factorial=1
>>> if num<0:
print("factorial does not exist for nagative numbers")
elif num==0:
print("the factorial of 0 is 1")
else:
for i in range(1,num+1):
factorial=factorial*i
print("the factorial of",num,"is",factorial)
OUTPUT:
the factorial of 6 is 1
the factorial of 6 is 2
the factorial of 6 is 6
the factorial of 6 is 24
the factorial of 6 is 120
the factorial of 6 is 720
(b)Factorial using while loop
>>> num=int(input("enter a number:"))
>>> fac=1
>>> i=1
>>> while i<=num:
fac=fac*i
i=i+1
print("factorial of",num,"is",fac)
OUTPUT:
enter a number:4
factorial of 4 is 1
factorial of 4 is 2
factorial of 4 is 6
factorial of 4 is 24
[Link]:
#USER DEFINED FUNCTIONS
def add(x,y):
return x+y
def subtract(x,y):
return x-y
def multiply(x,y):
return x*y
def divide(x,y):
return x/y
print(“select operation”)
print(“[Link]”)
print(“[Link]”)
print(“[Link]”)
print(“[Link]”)
choice=input(“enter choice (1/2/3/4):”)
num 1=int(input(“enter first number:”))
num 2=int(input(“enter second number:”))
if choice==’1’:
print(num 1,”+”,num 2,”=”,add(num 1,num 2))
elif choice ==’2’:
print(num 1,”-”,num 2,”=”,subtract(num 1,num 2))
elif choice ==’3’:
print(num 1,”*”,num 2,”=”,multiply(num 1,num 2)) elif choice ==’4’:
print(num 1,”/”,num 2,”=”,divide(num 1,num 2))
else :
print(“Invalid input”)
OUTPUT:
Select operation
[Link]
[Link]
[Link]
[Link]
Enter choice(1/2/3/4): 1
Enter First number: 10
Enter Second number: 20
10+20= 30
[Link]:
#EXCEPTION
try:
num = int(input("Enter the Input"))
re = 100/num
except(ValueError,ZeroDivisionError):
print("Something is wrong")
else:
print("Result",re)
#EXCEPTION HANDLING
try:
num = int(input("Enter the number"))
if(num<=0):
raise ValueError("That is not positive number")
except ValueError as error:
print(error)
OUTPUT:
Enter the Input 0
Something is wrong
Enter the number -1
Result -100.0
[Link] :
#parent class
>>> class dep:
def dept(self):
print("department")
#derived class
>>> class csca(dep):
def course(Self):
print("computer science")
print("computer applicaion")
>>> class year(csca):
def classes(self):
print("Iyear,IIyear,IIIyear")
>>> d=year()
>>> [Link]()
>>> [Link]()
>>> [Link]()
OUTPUT:
department
computer science
computer application
Iyear,IIyear,IIIyear
[Link]:
class Polygon:
def area(self):
pass
class triangle(Polygon):
def area(self):
width = 20
height = 10
area = (width * height) / 2
print(“calculate area of triangle and rectangle”)
print(“The area of the triangle is:”,+area)
class rectangle(Polygon):
def area(self):
width = 20
height = 10
area = (width * height)
print("The area of the rectangle is:",+area)
tr = triangle()
[Link]()
re = rectangle()
[Link]()
OUTPUT:
calculate area of triangle and rectangle
The area of the triangle is: 100.0
The area of the rectangle is: 200
[Link]:
text_file=open(“[Link]”,’w’)
text_file.write(“Shri sakthikailassh women’s college”)
text_file.close()
text_file=open(“[Link]”,’a’)
text_file.write(“Ammapet”)
text_file.write(“MSC computer science”)
text_file.close()
text_file=open(“[Link]”,’r’)
print(“welcome to sswc”)
text_file.close()
OUTPUT:
Welcome to sswc
[Link]:
#module1
#save the file name as [Link]
def greeting(name):
print("Have a nice day, " + name)
# save the file name as [Link]
import pro
[Link]("my dear friends")
#module2
#save the file name as [Link]
person1 = {
"name": "Nivetha",
"age": 22,
"country": "Erode"
}
#save the file name as [Link]
import mymodule
a = mymodule.person1
print(a)
OUTPUT:
[Link]: ([Link])
from flask import Flask, redirect, url_for, request
app = Flask(__name__)
@[Link]('/success/<name>')
def success(name):
return 'welcome %s' % name
@[Link]('/login',methods = ['POST', 'GET'])
def login():
if [Link] == 'POST':
user = [Link]['nm']
return redirect(url_for('success',name = user))
else:
user = [Link]('nm')
return redirect(url_for('success',name = user))
if __name__ == '__main__':
[Link](debug = True)
CODING: [Link]
<html>
<body><center>
<h1> WELCOME TO SSWC ............<h1>
<img src="e:\[Link]">
<form action = "[Link] method = "post">
<p>Enter Name:</p>
<p><input type = "text" name = "nm" /></p>
<p><input type = "submit" value = "submit" /></p>
</form></center>
</body>
</html>
Steps to run the program:
OUTPUT:
WELCOME TO SSWC…
Enter your name
priya
Welcome to computer science priya