computer science class 11 Lab 2024_2025
computer science class 11 Lab 2024_2025
AIM: Write a Python program that prompts the user to input student details (such as name, father name, mother
name, class, age, school, and city) and then prints those details.
#Program:
#program for taking student details
n=input("Enter your name ")
f=input("Enter your fahter name ")
m=input("Enter your mother name ")
cls=input("Enter your class ")
a=int(input("Enter your age "))
scl=input("Enter your school name ")
city=input("Enter your city ")
print("---------------Student details------------------------")
print("Name of the student :",n)
print("Father name :",f)
print("Mother name :",m)
print("class :",cls)
print("Age :",a)
print("Name of the school :",scl)
print("city :",city)
print("")
print("------------------------------------------------------")
2. AIM: Write a Python program to determine whether a given number is even or odd.
#Program
Output:
Enter a number: 97
97 is odd
Result:
Program has been executed successfully
3. AIM: Write a Python program that performs basic arithmetic operations (addition, subtraction, multiplication,
division) based on user selection. The user should choose an operation and then input two numbers to perform the
calculation.
#Program
a=int(input("Enter value 1 : "))
b=int(input("Enter value 2 : "))
option=input("Enter one option (add,sub,div,mul):\n")
if option=="add":
result=a+b
print(result)
elif option=="sub":
result=a-b
print(result)
elif option=="div":
if b==0:
print("Can’t be solved")
else:
result=a/b
print(result)
elif option=="mul":
result=a*b
print(result)
else:
print("wrong input,program stopped")
4. AIM: Write a Python program to check whether a given number is prime or not.
Program:
num = int(input("number"))
if num > 1:
for i in range(2,num):
if num % i == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
else:
print(num, "is not a prime number")
5. AIM: Write a Python program to calculate a student's grade based on the marks inputted by the user."
Program:
print("Enter Marks Obtained in 5 Subjects: ")
sub1 = int(input("Enter English marks: ")))
sub2 = int(input("Enter Math marks: "))
sub3 = int(input("Enter Physics marks: "))
sub4 = int(input("Enter Chemistry marks: "))
sub5 = int(input("Enter Computer marks: "))
tot = sub1+sub2+sub3+sub4+sub5
avg = tot/5
if num > 1:
is_prime = True # Assume the number is prime initially
if is_prime:
print(num, "is a prime number.")
else:
print(num, "is a composite number.")
elif num == 1:
print(num, "is neither prime nor composite.")
else:
print(num, "is not a valid input. Please enter a positive integer.")
8.AIM: Write a python program to Compute the greatest common divisor and least common multiple of two
integers.
Program:
a = int(input("Enter 1st number: "))
b = int(input("Enter 2nd number: "))
# Store original values for later use
original_a = a
original_b = b
# Using Euclidean Algorithm to find GCD
while b:
a, b = b, a % b
gcd = a # Store GCD
print("GCD is:", gcd)
# LCM PROGRAM
# Start with the maximum of the two original numbers
lcm = max(original_a, original_b)
# Use a for loop to find the LCM
for i in range(lcm, (original_a * original_b) + 1):
if i % original_a == 0 and i % original_b == 0:
lcm = i
break # Found the LCM
Program:
x = float(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
# b. Program
row = int(input("Enter number of rows: "))
for i in range(1, row + 1):
# Print leading spaces
for j in range(1, row - i + 1):
print(" ", end="")
# Print stars
for k in range(0, i):
print("*", end="")
print()
12. AIM: Write a python program to print following pattern.
1 1
12 22
123 333
1234 4444
12345 55555
#a_Program:
n = int(input("Enter number of rows: "))
# Outer loop to handle the rows
for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end="")
print()
#a_Program:
n = int(input("Enter number of rows: "))
# Outer loop to handle the rows
for i in range(1, n + 1):
for j in range(i):
print(i, end="")
print()
13. AIM: Write a python program to print following pattern.
A ****
AB ***
ABC **
ABCD *
#a_Program:
n = int(input("Enter number of rows: "))
# Outer loop to handle the rows
for i in range(1, n + 1):
for j in range(i):
print(chr(65 + j), end="")#chr(65) is 'A',this prints the alphabet
print()
#a_Program:
n = int(input("Enter number of rows: "))
# Outer loop to handle the rows
for i in range(n, 0, -1):
# Inner loop to print stars
for j in range(i):
print("*", end="")
print()
14. Write a Python program that takes a string and a specific word as input from the user, and counts how many
times the specific word occurs in the given string.
#Program:
# Initialize an empty string
text = ""
while True:
user_input = input("Enter a string: ")
text += user_input + " " # Append the input to the text with space
if opt.lower() == 'yes':
continue
elif opt.lower() == 'no':
break
for i in words:
if i.lower()==word_to_count.lower():
count += 1
Vow = 'aeiouAEIOU'
for ch in Text:
if ch in Vow:
c3=c3+1
elif ch.isalpha() and ch not in Vow:
c4=c4+1
print("The number of lower characters ",c1)
print("the number of upper characters ",c2)
print("The number of vowel characters ",c3)
print("the number of consonant characters ",c4)
16. Write a program that takes a string and replaces all vowels in the string with '*' character.
# Program:
st = input("Enter a String: ")
# Initialize an empty string to store the modified string
newstr = ''
print("Original List:", L)
print('original list',my_list)
print('original list',my_list)
#Finding maximum
Max=0
for i in range(len(my_list)):
if my_list[i]>Max:
Max=my_list[i]
print("The lasrgest number is:",Max)
22. Write a program to swap elements at the even location with the element’s odd location.
#Program:
#Program:
n=int(input("Enter the number of elements:"))
Ls=[]
for i in range(n):
val=int(input("Enter element:"))
Ls.append(val)
print("The original list:",Ls)
24. Write a Python program that creates a list of strings. The program should then identify the strings from the list
that do not contain any vowels. These strings should be pushed into a new list called NoVowel. Finally, the program
should print the NoVowel list containing all the strings that do not have vowels.
#Program:
strings_list = []
n=int(input('Enter no of elements to be inserted'))
for i in range(n):
ele=input('Enter element')
strings_list.append(ele)
NoVowel = []
for string in strings_list:
has_vowel = False
for char in string:
if char in "aeiouAEIOU":
has_vowel = True
break # Exit the loop if a vowel is found
for i in range(n):
element=int(input('Enter element :'))
My_List.append(element)
26. Create a nested list where each element represents a student with three elements: the roll number,
name, and marks. Then, implement a search functionality that allows the user to search for a student's
name based on a given roll number. If the roll number is found, display the student's name, marks;
otherwise, display an appropriate message indicating that the student was not found.
#Program:
students = []
for i in range(n):
data=[Roll_no,na,ma]
students.append(data)
found = 0
if stu[0] == search_roll_number:
print("Name:",stu[1])
print('Marks:' ,stu[2])
found = 1
break
if found==0:
27. Create a nested list with roll number, name and marks. Input a roll number and update the marks. if roll
number is not found display appropriate message.
#Program
students = []
for i in range(n):
data=[Roll_no,na,ma]
students.append(data)
print('created list',students)
found=0
for i in students:
if i[0]==roll_no:
found=1
break
if found==0:
else:
stu_dict = {}
for _ in range(n):
stu_dict[roll_no] = name
print('student data:',stu_dict)
f=0
for i in stu_dict:
if i==roll_number:
f=1
break
if f==0:
29.Write a python program to take a sentence and count occurrences of each word in the sentence.
#Program:
sentence = input("Enter a sentence: ")
words = sentence.split()
word_count = {}
for w in words:
if w in word_count: #word is already in the dictionary, increment it
word_count[w] += 1
else:
word_count[w] = 1 #add the word to the dict with a count of 1.
# Deleting a student
delete_name = input("Enter the name of the student to delete: ")
if delete_name in students:
del students[delete_name]
print(f"{delete_name} has been deleted from the records.")
else:
print(f"Student {delete_name} not found!")
31. Create a dictionary with the roll number, name and marks of n students in a class and display the
names of students who have scored marks above 75.
# Program:
n = int (input ("Enter number of students: "))
Stu_data = {}
for i in range(n):
print(f"Enter Details of student No. {i+1}")