You are on page 1of 17

CBSE Project File 1

Name: - Harsh Sengar


Class: - XII A
Roll No.: - 19
Adm. No.: - 8245
Subject: - Computer Science
CBSE Project File 1
6

The Satisfaction That Accompanies that the Successful


Completion Of Any Task Would Be Incomplete Without The
Mention Of People Whose Ceaseless Cooperation Made It
Possible. Whose Constant Guidance And Encouragement
Crown All Efforts With Success.

I Am Grateful To My Project Guide Mr. MOHIT SHARMA For The


Guidance , Inspiration & Constructive Suggestions That’s Help
Me In The Preparation Of This Project.

Last But Not The Least I Wish To Avail Myself For This
Opportunity.

Express A Sense Of Gratitude And Love To My Friends And


My Beloved Parents For Their Manual Support, Strength And Help.

Thanking You

Harsh Sengar

XII-A

Index
CBSE Project File 1
6

S. No. Topic Page No.


A program to arrange the
elements in ascending order
4
1. using Bubble Sort
A program to find the position of
2. element using Binary Search 6
A program to use read and write
3. function using Data File Handling 8
A program to display current date
4. and time 9
A program to sort elements using
5. Insertion Sort 10
6.
A program to create Calculator
11
A program to display Fibonacci
7. Series 14
A program to display output line by
8. line using Data File Handling 17
1.Bubble Sort Program

Input:
def bubbleSort(arr):
CBSE Project File 1
6

n = len(arr)

for i in range(n):

for j in range(0, n-i-1):


if arr[j] >
arr[j+1]:

arr[j], arr[j+1] = arr[j+1], arr[j]

arr = input('Enter the sorted list of


numbers: ') arr = arr.split() arr =
[int(x) for x in arr] bubbleSort(arr)

print ("Sorted array is:")


for i in range(len(arr)):
print ("%d" %arr[i])
CBSE Project File 1
6

Output:

2.Binary Search Program

Input:

def binary_search(alist, key):

"""Search key in alist[start... end -


CBSE Project File 1
6

1].""" start = 0

end = len(alist)

while start < end:

mid = (start + end)//2

if alist[mid] > key:

end = mid

elif alist[mid] < key:

start = mid + 1 else:

return mid return -1

alist = input('Enter the sorted list of

numbers: ') alist = alist.split() alist =


CBSE Project File 1
6

[int(x) for x in alist] key =

int(input('The number to search for:

'))

index = binary_search(alist, key) if

index < 0:

print('{} was not found.'.format(key)) else:

print('{} was found at index


{}.'.format(key, index))

Output:
CBSE Project File 1
6

3.To Use and Write function using Data File


Handling

Input:

f=open("rd.txt",'w') f.write("Hello\n")

f.write("Weather is good today\n\n")


f.write("Yeah, it is") print("Editing
completed") print("The Data in
the File is show below:")

f.close()
f=open("rd.txt")
print(f.read()) f.close()

Output:
CBSE Project File 1
6

4.To display Current Date and Time

Input:
import datetime
t_date=datetime.datetime.now()
print("Today is:",t_date)

Output:

5.Insertion Sort Program

Input:
CBSE Project File 1
6

a=[70,49,31,6,65,81,68]

print("Original List : ",a) for

i in a:

j=a.index(i)

while j>0:

if a[j-1]>a[j]:

a[j-1],a[j]=a[j],a[j-1]

else: break j=j-

print("List after sorting : ",a)


CBSE Project File 1
6

Output:

6.Calculator Program

Input:
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("1.Add") print("2.Subtract")
CBSE Project File 1
6

print("3.Multiply") print("4.Divide")
choice = input("Enter choice(1/2/3/4):

")
num1 = float(input("Enter first
number: ")) num2 =
float(input("Enter second
number: ")) if choice == '1':
print(num1,"+",num2,"=",
add(num1,num2)) elif choice ==
'2': print(num1,"-",num2,"=",
subtract(num1,num2)) elif choice
== '3': print(num1,"*",num2,"=",
multiply(num1,num2)) elif choice
CBSE Project File 1
6

== '4': print(num1,"/",num2,"=",
divide(num1,num2))
else:
print("Invalid input")

Output:

7.Fibonacci Series Program

Input:
CBSE Project File 1
6

nterms=int(input("Enter the Number


upto which the Fibonacci Series will
display:"))
n1=0 n2=1

count=0

tup=() if

nterms<=0:

print("Please enter a positive

integer") elif nterms==1:

print("Fibonacci sequence up

to",nterms,":") print(n1) else:


CBSE Project File 1
6

print("Fibonacci sequence up
to",nterms,":")
while count<nterms:

tup=tup+(n1,)

nth=n1+n2

n1=n2 n2=nth

count+=1

print(tup)

Output:
CBSE Project File 1
6

8.To display Output Line by Line

Input: f=open("rd.txt")

print(f.readline())

print(f.readline())

print(f.readline())

print(f.readline())

Output:
CBSE Project File 1
6

You might also like