python program
python program
print('Value entered:', x)
print('Type:', type(x))
p = float(input('Enter principle'))
r = float(input('Enter rate'))
t = float(input('Enter time'))
i=p*r*t/100
print("Interest=",i)
a=float(input('Enter a number'))
if a%2==0:
print(a,"is even")
else:
print(a,"is odd")
4. Program to check whether a number is divisible by 2 or 3 using nested if.
num=float(input('Enter a number'))
if num%2==0:
if num%3==0:
else:
else:
if num%3==0:
of values.
if choice==1 :
c=a+b
print("Sum=",c)
elif choice==2 :
c=a-b
print("Subtraction=",c)
elif choice==3 :
c=a*b
print("Multiplication=",c)
elif choice==4 :
c=a/b
print("Division=",c)
else :
print("Wrong choice")
eligible= a>=33
fail=a<20
if eligible :
print("Pass");
elif compartment :
print("compartment");
elif fail:
print("Fail");
sum=0
if num%2==0:
sum=sum+num
n=eval(input("Enter a number="))
i=1
f=1
while i<=n:
f=f*i #1*2*3*4*5
i=i+1
print("Factorial of",n,"=",f)
i=1
while i<=10:
print(n,"X",i,"=",n*i)
i=i+1
**
***
****
*****
for i in range(1,6):
print()
for j in range(1,i+1):
print ('*',end="")
print("Original List",aList)
n=len(aList)
for i in range(n-1):
for j in range(0,n-i-1):
if aList[j]>aList[j+1]:
aList[j],aList[j+1]=aList[j+1],aList[j]
print("Sorted List",aList)
length=len(L) #length=6
min=L[0] #min=10
loc=-1
if L[i]<min:
min=L[i] #min=1
loc=i
print("Minimum value=",min)
print("Location=",loc)
aDict={'Bhavna':1,"Richard":2,"Firoza":3,"Arshnoor":4}
val=eval(input('Enter value'))
flag=0
for k in aDict:
if val==aDict[k]:
flag=1
if flag==0:
14. Program to find largest among two numbers using a user defined function
def largest():
if a>b :
else:
return
largest()
15. Program to find sum of two numbers using a user defined function with
parameters.
def sum(a,b): #a and b are formal parameters
c=a+b
print("sum=",c)
sum(4,5)
sum(n1,n2)
16. Program to find simple interest using a user defined function with
def interest(p1,r1,t1 ):
i=p*r*t/100
return(i)
p=int(input("Enter principle="))
r=int(input("Enter rate="))
t=int(input("Enter rate="))
in1=interest(p,r,t)
print("Interest=",in1)
return
list1 = [10,20,30]
changeme( list1 )
return
printinfo("aman",45)
printinfo("Parth")
19. Program to write rollno, name and marks of a student in a data file
Marks.dat.
fileout=open("Marks.dat","a")
for i in range(count):
print("Enter details of student",(i+1),"below")
rollno=int(input("Enter rollno:"))
name=input("name")
marks=float(input('marks'))
rec=str(rollno)+","+name+","+str(marks)+"\n"
fileout.write(rec)
fileout.close()
fileinp=open("Marks.dat","r")
while str:
str=fileinp.readline()
print(str)
fileinp.close()
21. Program to read and display those lines from file that start with alphabet
‘T’.
file1=open("data.txt","r")
count=0
str1=file1.readlines()
print(str1)
for i in str1:
if i[0]=='T':
print (i)
file1.close()
22. Program to read and display those lines from file that end with alphabet
‘n’.
file1=open("data.txt","r")
count=0
str1=file1.readlines()
for i in str1:
if i[-2]=='n':
count+=1
file1.close()
file1=open("data.txt","r")
line=" "
count=0
while line:
line=file1.readline()
s=line.split()
for word in s:
count+=1
print("Number of words=",count)
file1.close()
file1=open("data.txt","r")
ch=" "
count=0
while ch:
ch=file1.read(1)
count+=1
print("Number of characters=",count)
file1.close()
import csv
fh=open("d:\student.csv","w")
stuwriter=csv.writer(fh)
stuwriter.writerow([1,'aman',50])
stuwriter.writerow([2,'Raman',60])
fh.close()
import csv
fh=open("d:\student.csv","r")
stureader=csv.reader(fh)
print(rec)
fh.close()
SQL Queries
SQL 1
(i) Display the Mobile company, Mobile name & price in descending order
of
their manufacturing date.
(ii) List the details of mobile whose name starts with “S”.
(iii) Display the Mobile supplier & quantity of all mobiles except “MB003‟.
(iv) To display the name of mobile company having price between 3000 &
5000.
MB004 450
MB003 400
MB003 300
MB003 200
2017-11-20 2010-08-21
AND M2.M_Qty>=300;
Classic Mobile
MB001 Galaxy 300
Store
SQL 2
theirHiredate.
ORDER BY HIREDATE;
ii. To display the TNAME and CITY of Trainer who joined the Institute in
AND ‘2001-12-31’;
iii. To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER
and COURSE of all those courses whose FEES is less than or equal to 10000.
GROUP BY CITY;
‘MUMBAI’);
Ans.
103 DEEPTI
106 MANIPRABHA
Ans.
101
103
102
104
105
vii. SELECT TID, COUNT(*), MIN(FEES) FROM COURSE GROUP BY TID HAVING
COUNT(*)>1;
Ans.
101 2 12000
09-15’;
Ans.
4 65000
SQL 3
iii ) To increase the fees of all courses by 500 of “System Design” Course.
Ans: 4
FACULTY.F_ID;
Ans: 6000
Ans: 60000
vii) Select avg(fees) from COURSES;
Ans: 17500
SQL 4
i. To display all the details of those watches whose name ends with ‘Time’
ii. To display watch’s name and price of those watches which have price
iv. To display watch name and their quantity sold in first quarter.
1 15
2 30
3 45
4 15
=s.watchid;
s.watchid;
HighTime 100 25 75
SQL 5
(i) To display the records from table student in alphabetical order as per the
order by name;
(ii ) To display Class, Dob and City whose marks is between 450 and 551.
(iii) To display Name, Class and total number of students who have secured
group by class
having marks> 450;
set marks=marks+20
where class=’XII’;
COUNT(*)>1;
2 Mumbai
2 Delhi
2 Moscow
08-12-1995 07-05-1993
Sanal F
Store M