0% found this document useful (0 votes)
10 views35 pages

Computer Project

ON DIFFRENT PYTHON LANGUAGES
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)
10 views35 pages

Computer Project

ON DIFFRENT PYTHON LANGUAGES
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

MARIAMPUR SENIOR SECONDARY

SCHOOL

COMPUTER PROJECT
PYTHON PROGRAMMING FILE

SUBMITTED TO SUBMITTED BY

MRS MEGHA CHELANI MEHAK KAPOOR

12-COMMMERCE

[Type the abstract of the document here. The abstract is typically a short summary of the contents
of the document. Type the abstract of the document here. The abstract is typically a short summary
of the contents of the document.]
ACKNOWLEDGEMENT
I would like to express my special thanks of
gratitude to my respected principal REV. SR.
RANJANA my teacher MRS.MEGHA CHELANI
for giving the opportunity to work on such
informative project and also for providing
their support and guidance . I would also like
to be thankful to my parents for their efforts
and endless support in the completion of this
project.
CERTIFICATE
This is to certify that MEHAK KAPOOR of
class
XII-COMMERCE of MARIAMPUR SENIOR
SECONDARY SCHOOL has successfully
completed her pyhthon programming file
under my guidance during the academic
session of 2022-2023 as per the guidance
issued by CENTRAL BOARD OF SECONDARY
EDUCATION

SIGNATURE
1. Write a program to find the maximum
of two numbers using conditional
operator.

a=int(input("enter the first no "))

b=int(input("enter the second no"))

if(a>b):

print("a is greater :")

else:

print("b is greater:")
2.Write a random number generator that generate random numbers
between 1 and 6(simulates a dice).

import random

def dice():

print("this is a game to roll a dice")

while True:

print("the dice is rolled")

a=random.randint(1,6)

print("you got",a)

b=input("do you want to play more?")

if b in "Nn":

break

print("thank you for playing")

dice()
3.Write the python program using
nested if construct to check a number
is positive or negative.
num=int(input("enter a number"))

if num>=0:

if num==0:

print("zero")

else:

print("positive number")

else:

print("negative number")
4. Write a program to display the table of a number in table
format.

n=int(input("enter the number"))

for i in range(1,11):

print(n,'*','=',n*i)
5.Write a program to display those place names,in which there are
more than 5 characters.

def COUNTNOW(PLACES):

for P in PLACES:

if len(P)>5:

print(P)

PLACES=["DELHI","LONDON","PARIS","NEW YORK"]

COUNTNOW(PLACES)
6.Write a program to display the sum and
difference of two numbers.
def add():

x=int(input("enter the value 1"))

y=int(input("enter the value 2"))

s=x+y

print(s)

def sub():

x=int(input("enter the value 1"))

y=int(input("enter the value 2"))

a=x-y

print(a)

while True:

print()

print("1 add")

print("2 sub")

print("3 exit")

print()

choice=int(input("enter the choice"))

if choice==1:

add()

elif choice==2:

sub()

elif choice==3:
break

7. Write a program to traverse a string.


str='python'
for i in str:

print(i)

8. Write a program to traverse dictionary.


p={"Shikha Anthony":"programmer","Anuj
Khan":"teacher","Shreya
Rao":"programmer","Hitesh
Khan":"programmer"}
for e in emp:
print(emp[e])
9.Write a program to traverse a list.
l=['p','y','t','h','o','n']
for x in l:
print(x)
10.Write a program to display first 10 natural
number in file “xyz.txt”.
f1=open("xyz.txt","w")
for x in range(1,11):
f1.write(str(x))
f1.close()
11.Write a program to display those lines from
textfile which are starting with capital “T”.
def disp():
f1=open("abc.txt")
line=f1.readline()
while(line):
if line[0]=="T":
print(line)
line=f1.readline()
f1.close()
disp()
12.Write a program to write in binary file.
import pickle
f1=open("abc.dat","wb")
t1=[]
pickle.dump(t1,f1)
print("writen")
f1.close()

13.Write a program to print the last line of the


text file “abc.txt”.
f1=open("abc.txt","r")
d=f1.readlines()
print(d[-1])
Csv program
14.Write a program to record the
student(name,roll no,marks)
import csv
f1=open("abc.txt","w")
sw=csv.writer(f1)
sw.writerow(["roll no","name","marks"])
for i in range(3):
print("student record",i+1)
roll=int(input("enter roll"))
name=input("enter name")
marks=int(input("enter marks"))
record=[roll,name,marks]
sw.writerow(record)
print("done")
f1.close()

Stack program
15.Write a program to perform the basic
operation on a stack using list like
creating,adding,showing and removing stack
element.
stack=list()
top=-1
#adding element into stack
def push_element(stack,top):
ch='Y'
while ch=='Y':
val=input("enter the value to be added in the
stack:")
stack.append(val)
top+=1
print("do you want to add
more..<y/n>:",end="")
ch=input()
if ch=='N':
break
return top
#removing stack element
def Pop_element(stack,top):
slen=len(stack)
if slen<=0:
print("stack is empty")
else:
val=stack.pop()
top=top-1
print("value deleted from stack is",val)
return top
#showing stack elements
def show_element(stack,top):
slen=len(stack)
if slen<=0:
print("stack is empty")
else:
print(" the stack elements are..,")
i=top
while(i>=0):
print(stack[i])
i-=1
while(True):
print()
print('STACK OPERATION')
print('-------------')
print('1.adding element to a stack')
print('2.removing elements from stack')
print('3.showing elements of a stack')
print('4.exit from stack operation')
print()
if(opt==1):
top=Push_element(Stack,top)
elif(opt==2):
top=Pop_element(Stack,top)
elif(opt==3):
show_element(Stack,top)
elif(opt==4):
break
16.write a program to append stack.
stack=[]
stack.append('a')
stack.append('b')
stack.append('c')
print('initial stack')
print(stack)

#pop()function to pop
#element from stack in
#LIFO order
print('\nelements popped from stack:')
print(stack.pop())
print(stack.pop())
print(stack.pop())

print('\nstack after elements are popped:')


print(stack)
PYTHON-SQL INTERFACE
19. Write a program to update the marks
of students in the table mode as marks
=60.
import mysql.connector as ms

mycon=ms.connect(host = "localhost" , user = "root" ,

password = "mysql123" , database = "data")

if mycon .is_connected():

print("successful connection...")

cur=mycon.cursor()

query="update mode set marks = 60"

cur.execute(query)

mycon.commit()
output

SQL
20 Write a program to display all the
data of the table mode.
import mysql.connector

mycon=mysql.connector.connect(host='localhost' ,

user='root' , password='mysql123' , database='data')

if mycon.is_connected():

print("Successful connection...")

cur=mycon.cursor() cur.execute("select * from mode")

data=cur.fetchall()

for i in data:

print(i)
21 Write a program to count the number
of rows in the table mode.
import mysql.connector as ms

mycon=ms.connect(host = "localhost" , user = "root" ,

password = "mysql123" , database = "data")

if mycon .is_connected():

print("successful connection...")

cur=mycon.cursor()

cur.execute("select * from mode")

data=cur.fetchall()

for i in data:

print(i)

print("Total no of rows:" , cur.rowcount)

print('---------------------‘)

You might also like