0% found this document useful (0 votes)
61 views9 pages

Computer Project Class 11 Cbse

Uploaded by

souryya2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views9 pages

Computer Project Class 11 Cbse

Uploaded by

souryya2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

COMPUTER PROJECT

NAME=SOURYYA CHAKRABORTY

CLASS=11

SEC=SCI-1

ROLL=31

1. Program to Split Even and Odd Elements into Two Lists


a=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
even=[]
odd=[]
for j in a:
if(j%2==0):
even.append(j)
else:
odd.append(j)
print("The even list",even)
print("The odd list",odd)
output=

2. Write a Python program to check if each number is prime in a


given list of numbers. Return True if all numbers are prime otherwise
False.
ower_value = int(input ("Please, Enter the Lowest Range Value: "))
upper_value = int(input ("Please, Enter the Upper Range Value: "))

print ("The Prime Numbers in the range are: ")


for number in range (lower_value, upper_value + 1):
if number > 1:
for i in range (2, number):
if (number % i) == 0:
break
else:
print (number)

OUTPUT=

3. Check for Descending Sorted List

test_list = [10, 8, 4, 3, 1]

# printing original list


print ("Original list : " + str(test_list))

flag = 0
i = 1
while i < len(test_list):
if(test_list[i] > test_list[i - 1]):
flag = 1
i += 1

# printing result
if (not flag) :
print ("Yes, List is reverse sorted.")
else :
print ("No, List is not reverse sorted.")
output=

3.BUBBLE SORT
my_list = [64, 34, 25, 12, 22, 11, 90]

n = len(my_list)

# Traverse through all elements in the list


for i in range(n):
# Last i elements are already sorted, so we don't need to check them
for j in range(0, n - i - 1):
# Swap if the element found is greater than the next element
if my_list[j] > my_list[j + 1]:
my_list[j], my_list[j + 1] = my_list[j + 1], my_list[j]

# Print the sorted array


print("Sorted array:", my_list)
output=

4.BINARY SEARCH
# Binary search without a function and with user input
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Get user input for the target element


target = int(input("Enter the number to search: "))

low, high = 0, len(my_list) - 1


found = False

while low <= high:


mid = (low + high) // 2

# Check if the target is present at the mid


if my_list[mid] == target:
found = True
break
# If the target is greater, ignore the left half
elif my_list[mid] < target:
low = mid + 1
# If the target is smaller, ignore the right half
else:
high = mid - 1

# Print the result


if found:
print(f"Element {target} is present at index {mid}")
else:
print(f"Element {target} is not present in the list")

OUPUT=

5.SELECTION SORT
# Selection sort without a function
my_list = [64, 34, 25, 12, 22, 11, 90]
n = len(my_list)

# Traverse through all elements in the list


for i in range(n):
# Find the minimum element in the unsorted part
min_index = i
for j in range(i + 1, n):
if my_list[j] < my_list[min_index]:
min_index = j

# Swap the found minimum element with the first element


my_list[i], my_list[min_index] = my_list[min_index], my_list[i]

# Print the sorted array


print("Sorted array:", my_list)

OUTPUT=

6.RIGHT SHIFT
# Tuple program with right shift
original_tuple = (1, 2, 3, 4, 5)
shift_distance = 2
# Perform right shift
shifted_tuple = original_tuple[-shift_distance:] + original_tuple[:-
shift_distance]

# Print the original and shifted tuples


print("Original Tuple:", original_tuple)
print("Shifted Tuple:", shifted_tuple)

OUTPUT=

7.SIZE OF A TUPLE
import sys

# sample Tuples
Tuple1 = ("A", 1, "B", 2, "C", 3)
Tuple2 = ("Geek1", "Raju", "Geek2", "Nikhil", "Geek3", "Deepanshu")
Tuple3 = ((1, "Lion"), ( 2, "Tiger"), (3, "Fox"), (4, "Wolf"))

# print the sizes of sample Tuples


print("Size of Tuple1: " + str(sys.getsizeof(Tuple1)) + "bytes")
print("Size of Tuple2: " + str(sys.getsizeof(Tuple2)) + "bytes")
print("Size of Tuple3: " + str(sys.getsizeof(Tuple3)) + "bytes")

OUTPUT=

8.ADDING LIST AND TUPLE


# Python3 code to demonstrate working of
# Adding Tuple to List and vice - versa
# Using += operator (list + tuple)

# initializing list
test_list = [5, 6, 7]

# printing original list


print("The original list is : " + str(test_list))

# initializing tuple
test_tup = (9, 10)
# Adding Tuple to List and vice - versa
# Using += operator (list + tuple)
test_list += test_tup

# printing result
print("The container after addition : " + str(test_list))

OUTPUT=

9.CUBE OF TUPLE ELEMNTS


# Python program to create a list of tuples
# from given list having number and
# its cube in each tuple

# creating a list
list1 = [1, 2, 5, 6]

# using list comprehension to iterate each


# values in list and create a tuple as specified
res = [(val, pow(val, 3)) for val in list1]

# print the result


print(res)

OUPUT=

10.SUM OF TUPLE ELEMENTS


# Python 3 code to demonstrate working of
# Tuple elements inversions
# Using map() + list() + sum()

# initializing tup
test_tup = ([7, 8], [9, 1], [10, 7])

# printing original tuple


print("The original tuple is : " + str(test_tup))
# Tuple elements inversions
# Using map() + list() + sum()
res = sum(list(map(sum, list(test_tup))))

# printing result
print("The summation of tuple elements are : " + str(res))

OUTPUT=

11.SORT DICTIONARY FROM KEY AND VALUES


myDict = {'ravi': 10, 'rajnish': 9,
'sanjeev': 15, 'yash': 2, 'suraj': 32}

myKeys = list(myDict.keys())
myKeys.sort()
sorted_dict = {i: myDict[i] for i in myKeys}

print(sorted_dict)

OUTPUT=

12.SUM OF ALL ITEMS IN DICTIONARY


# Sample dictionary
my_dict = {'a': 10, 'b': 20, 'c': 30, 'd': 40}

# Calculate the sum of all items in the dictionary


sum_of_items = sum(my_dict.values())

# Print the result


print("Sum of all items in the dictionary:", sum_of_items)

OUTPUT=
13.SIZE OF DICTIONARY
import sys

# sample Dictionaries
dic1 = {"A": 1, "B": 2, "C": 3}
dic2 = {"Geek1": "Raju", "Geek2": "Nikhil", "Geek3": "Deepanshu"}
dic3 = {1: "Lion", 2: "Tiger", 3: "Fox", 4: "Wolf"}

# print the sizes of sample Dictionaries


print("Size of dic1: " + str(sys.getsizeof(dic1)) + "bytes")
print("Size of dic2: " + str(sys.getsizeof(dic2)) + "bytes")
print("Size of dic3: " + str(sys.getsizeof(dic3)) + "bytes")

OUTPUT=

14. KEY WITH MAXIMUM SPECIAL CHARACTER


# Python3 code to demonstrate working of

# Key with maximum unique values


# Using loop

# initializing dictionary
test_dict = {"Gfg": [5, 7, 5, 4, 5],
"is": [6, 7, 4, 3, 3],
"Best": [9, 9, 6, 5, 5]}

# printing original dictionary


print("The original dictionary is : " + str(test_dict))

max_val = 0
max_key = None

for sub in test_dict:

# Testing for length using len() method and


# converted to set for duplicates removal
if len(set(test_dict[sub])) > max_val:
max_val = len(set(test_dict[sub]))
max_key = sub

# Printing result
print("Key with maximum unique values : " + str(max_key))
OUTPUT=

15.MERGING OF TWO DICTIONARY


# Two sample dictionaries
dict1 = {'a': 10, 'b': 20}
dict2 = {'b': 30, 'c': 40}

# Merge dictionaries using update() method


dict1.update(dict2)

# Print the merged dictionary


print("Merged Dictionary:", dict1)

OUTPUT=

You might also like