Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
24 views

Computer Project: Made By

This document contains the computer project made by Ashwat Prakash in 2019. It includes Python programs to solve various problems - segregating odd and even elements of a list, creating a dictionary of competition winners and their wins, sorting lists using bubble sort and selection sort, binary search, generating random numbers, finding the nth Fibonacci number recursively, and performing arithmetic operations on two numbers passed to a function. It also includes SQL questions on creating tables, inserting records, using aggregate functions, and joining tables. Finally, it contains Python programs to copy data between files, extract words starting with 'A' from one file to another, display hash marks after words in a file along with its size, and split lines starting with '

Uploaded by

Asha Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Computer Project: Made By

This document contains the computer project made by Ashwat Prakash in 2019. It includes Python programs to solve various problems - segregating odd and even elements of a list, creating a dictionary of competition winners and their wins, sorting lists using bubble sort and selection sort, binary search, generating random numbers, finding the nth Fibonacci number recursively, and performing arithmetic operations on two numbers passed to a function. It also includes SQL questions on creating tables, inserting records, using aggregate functions, and joining tables. Finally, it contains Python programs to copy data between files, extract words starting with 'A' from one file to another, display hash marks after words in a file along with its size, and split lines starting with '

Uploaded by

Asha Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

2019

COMPUTER PROJECT

MADE BY:-
ASHWAT PRAKASH
QUES) WRITE A PROGRAM TO SEGREGATE ODD AND EVEN ELEMENTS OF
A LIST?

list=[]

choice="y"

while choice=="y":

num=int(input("Enter The Number :-"))

list.append(num)

choice=input("Enter Your Choice")

list_even=[]

list_odd=[]

for i in list:

if i%2==0:

list_even.append(i)

else:

list_odd.append(i)

list3=list_odd + list_even

print(“The original list is”,list)

print(“The sorted list is”,list3)

QUES) CREATE A DICTIONARY CONTINING NAMES OF COMPETITION


WINNERS, STUDENT AS KEYS AND NO OF THEIR WINS AS VALUES AND
DISPLAY THE NAME OF STUDENT WITH MAX WINS?

dict={}

n=int(input("How Many Students ?"))

for i in range(n):

key=input("Name Of Student:-")

value=int(input("No Of Their Wins"))

dict[key]=value

print(“The original dictionary is”,dict)

Maxwin=max(dict.items(), key=lambda k: k[1])

print("Maximum wins",Maxwin)
QUES) SORT A LIST IN DESCENDING ORDER USING BUBBLE SORT

arr=[1,5,6,4,88,9,7,6,5,4,33,34,5,66,666]

print("List before sorting",arr)

n = len(arr)

for i in range(n):

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

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

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

print(“List after sorting with bubble sort”,arr)

QUES) SORT A LIST IN ASCENDING ORDER USING SELECTION SORT

arr=[1,5,6,4,88,9,7,6,5,4,33,34,5,66,666]

print("List before sorting",arr)

for i in range(len(arr)):

min_idx = i

for j in range(i+1, len(arr)):

if arr[min_idx] > arr[j]:

min_idx = j

arr[i], arr[min_idx] = arr[min_idx], arr[i]

print("List after sorting with selection sort",arr)


QUES) BINARY SEARCH

def bin_search(my_list,item):

start=0

last=len(my_list)-1

while start<=last:

mid=(start+last)//2

if item==my_list[mid]:

return mid

elif item>my_list[mid]:

start=mid

else:

last= mid

else :

return False

QUES)WAP TO GENERATE A RANDOM NUMBER GENERATOR BETWEEN 1


AND 6

import random

int=random.randint(1,6)

print("The random number generated is",int)


QUES)WRITE A RECURSIVE CODE TO FIND THE NTH FIBONACCI NUMBER

def Fibonacci(num):

if num<=1:

return 0

if num==2:

return 1

num1=Fibonacci(num-1)

num2=Fibonacci(num-2)

n=num1 + num2

print(“The nth Fibonacci number is”, n)

QUES)WRITE A PROGRAM THAT RECIEVES TWO NO IN A FUNCTION

num1= int(input("Enter the 1st number"))

num2=int(input("Enter the second number"))

add = num1 + num2

dif = num1 - num2

mul = num1 * num2

div = num1 / num2

print('Sum of ',num1 ,'and' ,num2 ,'is :',add)

print('Difference of ',num1 ,'and' ,num2 ,'is :',dif)

print('Product of' ,num1 ,'and' ,num2 ,'is :',mul)

print('Division of ',num1 ,'and' ,num2 ,'is :',div)


QUES)WRITE A FUNCTION THAT WILL SWAP THE VALUES OF TWO
VARIABLES

def Swap():

x=int(input("Enter The First Number :-"))

y=int(input("Enter The Second Number :-"))

print(“The Values of the variables are x=”,x,”y=”,y)

x,y=y,x

print(“The Values of the switched variables are “,x,y)


SEQUEL

QUES)CREATE A TABLE STUDENT WITH 10 DUMMY RECORDS?

TABLE

ADD
DELETE

UPDATE
QUES)IN THE PREVIOUS TABLE , USE ALL THE AGGREGATE FUNCTIONS
(MIN, MAX, SUM ,AVERAGE) ON MARKS COLUMN

MAX

MIN

SUM
AGGREGATE
QUES)ADD A COLUMN ”HOUSE” AND DISPLAY THE NO OF STUDENTS IN
EACH HOUSE

Q13) CREATE 2 DUMMY TABLES AND JOIN THEM USING RIGHT JOIN,
NON-EQUIVALENT JOIN, AND CARTESIAN JOIN.

Tables:
Right join:

Non-equivalent join:

Cartesian join.
QUES)WAP THAT WILL READ DATA FROM FILE1 AND COPY IT TO FILE 2

myfile=open("D:\\Txt File 1.txt","r")

file=open("D:\\Txt File 2.txt","w")

for i in myfile:

obj=file.write(i)

file.close()

QUES)WAP THAT WILL READ FROM FILE 1 AND COPY ALL THE WORDS
STARTING WITH ’ A ‘ IN FILE 2

myfile=open("D:\\Txt File 1.txt","r")

file=open("D:\\Txt File 2.txt","w")

str=myfile.read()

obj=str.split()

for i in obj:

if i[0]=="a":

app=file.write(i)

app=file.write("\n")

print(i)

file.close()
QUES)WAP THAT WILL DISPLAY”#” AFTER EVERY WORD OF FILE A AND
ALSO DISPLAY THE SIZE OF THE FILE

myfile=open("D:\\Txt File 1.txt","r")

str=myfile.read()

obj=str.split()

for i in obj:

print("#",i)

print("The size of the file is",len(str))

myfile.close()

QUES)WAP THAT WILL SPLIT ALL THE LINES STARTING WITH “P” ON
PARAMETER “,”.

file1=open("D:\\Txt File 1.txt","r")

while True:

data=file1.readline()

if len(data)==0:

break

if data[0].lower()=="p":

splitline=data.split(",")

print(splitline)

else:

continue

file1.close()

You might also like