0% found this document useful (0 votes)
21 views23 pages

Harsh CS

Computer science art integration

Uploaded by

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

Harsh CS

Computer science art integration

Uploaded by

himanshubby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 23
PRACTICAL FILE OF COMPUTER SCIENCE (083) SESSION 2024-25 BY HARSH JAISWAL (12103) UNDER GUIDANCE OF MRS. POOJA SINGH BAGHEL FOR PARTIAL FULFILMENT OF XII SCI. SUBMITTED TO BAL BHARATI PUBLIC SCHOOL NTPC SIPAT, BILASPUR CERTIFICATE This is to certify that Harsh Jaiswal of class XII has successfully completed the practical work with the help of Python and SQL language under my guidance and supervision. | am satisfied with his initiatives and efforts in completing the practical work, as a part of the CBSE curriculum for class XIl examination. Mrs. P.S. BAGHEL Mr. SHALABH NIGAM Internal Examiner (Principal) ACKNOWLEDGMENT lam greatly indebted to my Teacher Mrs. Pooja Singh Baghel for her effervescent encouragement and constructive guidance. | would like to express my gratitude to her for making me proficient in learning and understanding Python and helping me a lot in completing my work and assignment. | also give thanks to respected principal sir, Mr. Shalabh Nigam without whose cooperation this practical work wouldn’t have been completed. | am heartedly thankful to my parents, my family and my classmates who helped me through my work. 1. Write a program to check whether a number is palindrome or not using a user-defined function. def palindrome (number: if (number==number[::-1]): return "The number is apalindrome." else: return "The number is not apalindrome." no=input ("Enter number: ") print (palindrome (no) ) ourput Enter number: 121 The number is apalindrome. 2. Write a program to modify the given list, even numbers of a list must be increased by 5 and odd numbers must be decreased by 5, using a user-defined function. A= GE) Dy 3; 4p. Syn Ge A 8) def oddeven(1): result = [] for i inl: if it2==0: result.append(i + 5) else: result.append(i - 5) return result print (oddeven(1)) ourPuT [-4, 7, -2, 9, 0, 11, 2, 13] 3. Write a menu-driven program in Python using user-defined function to find. e Simple interest Compound interest Get gimple_interest (principal, rate, time): ‘Calculate and return Simple interest.""" return (principal * rate * time) / 100 def compound interest (principal, rate, time, 1 ‘Calculate and return Compound Interest. return principal * ((1 + rate / (100 * m)) ** (n * time) ~ principal der main): while True: print ("\nMenu:") Print("1. Calculate simple Interest”) print ("2. calculate Compound interest”) print ("3. Exit") choice = input ("Enter your choice (1/2/3): ") Af choice == 11" principal = float (input ("Enter the principal amount: ")) Fate = float (input ("Enter the rate of interest (in 4): ")) time = float (input ("Enter the time (in years): ")) siv= simple interest (principal, rate, time) print ("The Simple interest is:'*,si) elif choice == 12": Principal = float (input ("Enter the principal amount: *)) Fate = float (input ("Enter the rate of interest (in #): ")) time = float (input ("Enter the time (in years): ")) n= int (input ("Enter the number of tines interest is compounded per year: ")) ‘ci = compound_interest (principal, rate, time, n) print ("The Compound Interest is:'*,ci) elif choice == 13" print ("Exiting the program. Goodbye!") Break eis: print ("invalid choice! Please try again.") Af name = "_main_’ Tain (7 ourPuT Menu: 1. calculate simple Interest 2. Calculate Compound Interest 31 exit Enter your choice (1/2/3): 1. Enter the principal amount: 7000 Enter the rate of interest (in $): 8 Enter the time (in years): 3 ‘The Simple Interest is: 1680.0 Menu: 1. calculate simple Interest 21 calculate Compound Interest 3. Exit Enter your choice (1/2/3): 2 Enter the principal amount: 7000 Enter the rate of interest (in $): 8 Enter the time (in years): 3 Enter the number of times interest is compounded per year: 1 ‘The Compound Interest is: 1817.9840000000004 Menu: 1. Calculate simple Interest 21 calculate Compound Interest 3. Exit Enter your choice (1/2/3): 3 Exiting the program. Goodbye! 4. Write a menu-driven program in Python using user-defined function to find. @ Perimeter of a rectangle(2*length*breadth) © Circumference of a circle(2*3.14*r) def perimeter_rectangle (length, breadth) ;| return 2 * (length + breadth) def circumference_circle (radius) : return 2 * 3.14 * radius def main( while True: print ("\nMenu:") print("1. Calculate Perimeter of a Rectangle") print ("2. Calculate Circumference of a Circle”) print ("3. Exit") choice = input("Enter your choice (1/2/3): ") if choice == '1 length = float (input ("Enter the length of the rectangle: ")) breadth = float(input ("Enter the breadth of the rectangle: ")) perimeter = perimeter_rectangle (length, breadth) print (f"The Perimeter of the rectangle is: (perimeter:.2f}") elif choice == '2": radius = float (input ("Enter the radius of the circle: ")) circumference = circumference_circle (radius) print (f"The Circumference of the circle is: {circumference:.2f}") elif choice == '3': print ("Exiting the program. Goodbye break else: print ("Invalid choice! Please try again.") if _name 5 “main( "_main_' ourPUT Ment 1. Calculate Perimeter of a Rectangle 2. Calculate Circumference of a Circle 3. Exit Enter your choice (1/2/3): 1 Enter the length of the rectangle: 2 Enter the breadth of the rectangle: 2 The Perimeter of the rectangle is: 8.00 Ment 1. Calculate Perimeter of a Rectangle 2. Calculate Circumference of a Circle 3. exit Enter your choice (1/2/3): 2 Enter the radius of the circle: 2 The Circumference of the circle is: 12.56 Menu: 1. Calculate Perimeter of a Rectangle 2. Calculate Circumference of a Circle 3. Exit Enter your choice (1/2/3): 3 Exiting the program. Goodbye! 5. Write a program to perform push and pop operations on a stack in Python. Ast = [{'New York, 'USA', 800], ["Paris', 'France', 900], ["Bilaspur', 'India', 1130]] travel=[1 def Push_element (1st): for E in 1st: if L(1) != ‘Indiat and L{2] < 1000: travel.append({L(0}, L(1]]) def Pop_element (): if Ten(travel) > 0: print ("Popped element: ",travel.pop()) else: print ("stack Empty") Push_element (1st) Pop_element () ourpuT Popped element: ['Paris', 'France'] 6. Write a program to count the number of vowels present in a text file. f=open("c://SQL.txt", "r") -read() for i in s: if i.lower() in ["a', 'e', "i", 'o', ‘u']: d=d+1 print ("Number of vowels: ", d) ourPUT Number of vowels: 91 7. Write a program to count the number of ‘this’(ignore case) sopen("c://SQL.txt", "r") «read() -split() w d=0 for i in w: if i.lower( d=d+1 print ("Number of 'this': ", d) ourPuT Number of 'this': 4 8. Write a program to write those lines which have the character “p”, from one text file to another text file. with open("source.txt", "r") as s: with open("destination.txt", "w") as d: for i in s: if 'p' in i.lower(): d.write (line) print ("Lines containing 'p' have been written to 'destination.txt'") 9. Write a program to count the number of words in a text file. f=open("c://SQL.txt", "r") s=f.read() w=s.split () print ("Number of words:", len(w)) ourpuT Number of words: 64 10. Write a program to get Roll no., Names and Marks of the students of a class and store these details in a file called marks.dat. import pickle list =[ ] f=open("marks.dat", "ab") roll= int(input ("Enter roll no: ")) name= input ("Enter Students's name: ") marks= int (input ("Enter marks: ")) 1=[roll, name, marks] pickle. dump (1, £) £.close() ourPuT Enter roll no: 4 Enter Students's name: hardik Enter marks: 76 11. Write a program to display student's record of a class stored in a file called marks.dat import pickle try: with open("marks.dat", "rb") as print ("Records in the file: while True: try: record = pickle.load(f) print (record) except EOFError: break except FileNotFoundError: print ("The file does not exist.") ouTPUT Records in the file: [5, 'Kohli', 90] (1, 'kohli', 98] [2, 'Dhoni', 87] (3, "suresh", 100] [4, "hardik', 76] 12. Write a program to count the students of a class whose marks is greater than 90 stored in a file called “Marks.dat”. import pickle f=open("marks.dat", "rb") c=0 try: while True: x=pickle.load(f) if x[2]>90: Gres. except EOFError: f£.close() print ("Number of Student with >90 marks: ",c) ourpuT Number of Student with >90 marks: 2

You might also like