0% found this document useful (0 votes)
13 views17 pages

Practical12 032718

Uploaded by

Milan Dhara
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)
13 views17 pages

Practical12 032718

Uploaded by

Milan Dhara
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
You are on page 1/ 17

NAME= PRITI DAS

CLASS= XI

ROLL NO.= 17

SUBJECT= COMPUTER SCIENCE

1
INDEX
S.NO. TITLE Page no Teacher’s sign
1. Program to enter a string from user and 3.
performing various string functions
2. Program to enter the number of terms and 4.
to print the Fibonacci series
3. Program to find whether an inputted 5.
number from user is perfect square or not
4. Program to take Principal Amount, Time 5.
,Rate p. a from user and give the amount of
Simple Interest
5. Program to use statistics module to find 6.
mean and mode
6. Program to find the Surface Area and 6.
Volume of cylinder by taking radius and
height from user
7. Program to read the contents from file and 7.
adding to the text file
8. Program to add two numbers using text file 7.
9. Program to insert roll no. ,name and marks 8.
in binary file
10. Program to show the information inserted 9.
by user
11. Program to create a csv file by entering 9.
user_id and password
12. Program to drop column from table in SQL 10.
13. Program to create database in SQL using 11.
python and also showing the databases
using python
14. Program to get data in form of tuples in list 11.
using fetchall
15. Program to insert values in SQL table using 12.
python interfaces
16. Program on parameterized queries 12.
17. Parameterized query by getting input from 13.
user using old style
18. Program to implement stack operations 13.
using list
19. Random number generator that generates 14.
random numbers between 1 and 6
20. Student table and implement following 15.
command on the student table

2
3
PRO RAM TO ENTER A STRIN FROM USER AN PERFORMIN VARIOUS STRIN FUNCTIONS

INPUT: a=input("Enter your statement:")

print("1:FIND LENGTH OF THE STRING")


print("2:CONVERT THE FIRST LETTER OF THE STATEMENT")
print("3:CONVERT FIRST LETTER OF EVERY WORD")
print("4:CONVERT ENTIRE STRING INTO CAPITAL CASE")
print("5:CONVERT ENTIRE STRING INTO SAMLLER CASE")
print("6:FIND NO. OF OCCURENCES OF A SUBSTRING")
print("7:FIND INDEX POSITION OF THE SUBSTRING")
b=input("Enter your preferable choice:")
if b=='1':
print("Length of the string:",len(a))
elif b =='2':
print("After converting:",a.capitalize())
elif b=='3':
print("After converting:",a.title())
elif b=='4':
print("After converting:",a.upper())
elif b=='5':
print("After converting:",a.lower())
elif b=='6':
sub=input("Enter the substring:")
print("No. of occurrences :",a.count(sub))
elif b=='7':
sub2=input("Enter the substring:")
print("Index position:",a.find('sub2'))
else:
b=input("Enter your preferable option")

OUTPUT: Enter your statement: my name is priti das


1: FIND LENGTH OF THE STRING
2: CONVERT THE FIRST LETTER OF THE STATEMENT
3: CONVERT FIRST LETTER OF EVERY WORD
4: CONVERT ENTIRE STRING INTO CAPITAL CASE
5: CONVERT ENTIRE STRING INTO SAMLLER CASE
6: FIND NO. OF OCCURENCES OF A SUBSTRING
7: FIND INDEX POSITION OF THE SUBSTRING
Enter your preferable choice:6
Enter the substring:i
No. of occurrences : 3

4
PROGRAM TO ENTER THE NUMBER OF TERMS AND TO PRINT THE FIBONACCI SERIES

INPUT:

i=int(input("Enter the limit:"))


x=0
y=1
z=0
tup=()
if i<=0:
print("Please enter a positive integer")
elif i==1:
print("Fibonacci sequence up to",i,":")
print(x)
else:
print("Fibonacci series up to",i,":")
while z<i:
tup=tup+(x,)
nth=x+y
x=y
y=nth
z+=1
print(tup)

OUTPUT:

Enter the limit:5

Fibonacci series up to 5 :

(0,)

(0, 1)

(0, 1, 1)

(0, 1, 1, 2)

(0, 1, 1, 2, 3)

5
PROGRAM TO FIND WHETHER AN INPUTTED NUMBER FROM USER IS A PERFECT SQUARE
OR NOT.

INPUT:

import math
num=int(input("Enter the number:"))
sqrt_num=math.sqrt(num)
if sqrt_num.is_integer():
print("The number is a perfect square")
else:
print("The number is not a perfect square")

OUTPUT: 1

Enter the number:24

The number is not a perfect square

OUTPUT: 2

Enter the number:25

The number is a perfect square

PROGRAM TO TAKE PRINCIPAL AMOUNT ,TIME,RATE p.a. FROM USER AND GIVE THE
AMOUNT OF SIMPLE INTEREST

INPUT:

P=eval(input("Enter Principal:"))
T=eval(input("Enter time(in years):"))
R=eval(input("Enter the rate p.a:"))
SI=P*R*T/100
print('Rate=',R,'%p.a')
print("Simple interest = Rs",SI)

OUTPUT:

Enter Principal:1000
Enter time(in years):2
Enter the rate p.a:8
Rate= 8 %p.a
Simple interest = Rs 160.0

6
PROGRAM TO USE STATISTICS MODULE TO FIND MEAN AND MODE

INPUT:

import statistics
data=[2,3,3,4,4,4,5,5,5,5]
mean_value=statistics.mean(data)
mode_value=statistics.mode(data)
print("Mean:",mean_value)
print("Mode:",mode_value

OUTPUT:

Mean: 4

Mode: 5

PROGRAM TO FIND THE TOTAL SURFACE AREA AND VOLUME OF CYLINDER BY TAKING
RADIUS AND HEIGHT FROM USER

INPUT:

R=eval(input("Enter the radius of cylinder:"))


H=eval(input("Enter the height of cylinder:"))
TSA=2*3.14*R*H+3.14*R*R
VOL=3.14*R*R*H
print("Total Surface Area=",round(TSA,2),"sq. units")
print("Volume =",round(VOL,2),"Cu.units")

OUTPUT:1

Enter the radius of cylinder:3


Enter the height of cylinder:2
Total Surface Area= 65.94 sq. units
Volume = 56.52 Cu.units

OUPUT:2

Enter the radius of cylinder:7

Enter the height of cylinder:3

Total Surface Area= 285.74 sq. units

Volume = 461.58 Cu.units

7
PROGRAM TO READ THE CONTENTS FROM FILE AND ADDING TO THE TEXT FILE

INPUT:

f=open("NOTE.1.txt",'a+')
data=f.read()
print(data)
b=input("Type the string you want to add in file:")
f.write(b)
print("Data written to the file successfully")
f.close()

OUPUT:

Type the string you want to add in file: We are writting data to a text file

ata written to the file successfully

IN NOTEPA :

PROGRAM TO ADD TWO NUMBERS USING FILE

INPUT:

f=open("NOTE.1.txt",'a+')
data=f.read()
print(data)
b=input("Type the string you want to add in file:")
f.write(b)
print("Data written to the file successfully")
f.close()

OUTPUT:

Enter the first number:65.0

Enter the second number:98.0

Sum of two numbers: 163.0

IN NOTEPA :

8
PROGRAM TO INSERT ROLL NO,NAME NAD MARKS IN BINARY FILE

INPUT:

import pickle
def record():
f=open("bin.dat",'wb')
while True:
r=int(input("Enter Roll no.:"))
n=input("Enter name:")
m=float(input("Enter the marks:"))
data=[r,n,m]
pickle.dump(data,f)
choice=input("Do you want to enter more records(Y/N):")
if choice in 'Nn':
break
f.close()
record()

OUTPUT:

Enter Roll no.:2012

Enter name:priti

Enter the marks:65

o you want to enter more records(Y/N):Y

Enter Roll no.:657

Enter name:Neena

Enter the marks:87


o you want to enter more records(Y/N):n

IN CSV FILE:

9
PROGRAM TO SHOW THE INFORMATION INSERTED BY USER

INPUT:

import pickle
def read():
f=open("bin.dat",'rb')
try:
while True:
record=pickle.load(f)
print(record)
except EOFError:
f.close()
read()

OUTPUT:

[2012, 'priti', 65.0]

[657, 'Neena', 87.0]

PROGRAM TO CREATE A CSV FILE BY ENTERING USER_ID AND PASSWORD

INPUT:

import csv
def write():
f=open("BOOK2.csv",'w')
o=csv.writer(f)
o.writerow(["UserId","Password"])
while True:
id1=input("Enter user_id:")
pswd=input("Enter password:")
data=[id1,pswd]
o.writerow(data)
choice=input("Do you want to enter more records(Y/N):")
if choice in 'Nn':
break
f.close()
write()

OUPUT:

Enter user_id:priti

Enter password:8676

o you want to enter more records(Y/N):y

Enter user_id:Neena

10
Enter password:7784

o you want to enter more records(Y/N):n

IN EXCEL:

PROGRAM TO DROP COLUMN FROM TABLE IN SQL

SQL TABLE:

ELETE THE COLUMN “dateofleave”

SQL TABLE:

11
PROGRAM TO CREATE DATABASES IN SQL USING PYTHON AND ALSO SHOWING
THE DATABASES IN PYTHON

INPUT:

OUTPUT:

PROGRAM TO GET DATA IN FROM OF TUPLES IN LIST USING FETCHALL

INPUT:

OUPUT:

PROGRAM TO INSERT VALUES IN SQL TABLE USING PYTHON INTERFACES

INPUT:

12
OUTPUT:

IN SQL:

PROGRAM ON PARAMETERISED QUERIES

INPUT:

13
OUTPUT:

PARAMETERISED QUERY BY GETTING INPUT FROM USER USING OLD STYLE

INPUT:

OUTPUT:

PROGRAM TO IMPLEMENT STACK OPERATIONS USING LIST

INPUT:

14
OUPUT:

A RANDOM NUMBER GENERATOR THAT GENERATES RANDOM NUMBER BETWEEN 1 AND


6(IN DICE)

INPUT:

15
OUTPUT:

STUDENT TABLE AND IMPLEMENT FOLLOWING COMMAND ON THE STUDENT TABLE

INPUT:

➢ UPDATE TABLE to modify data


➢ ALTER TABLE to add new attributes

OUTPUT:UPDATE

16
OUTPUT:ALTER

17

You might also like