Sunteți pe pagina 1din 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()

S-ar putea să vă placă și