0% found this document useful (0 votes)
46 views18 pages

Compuooter

The document contains a lab record submission for a Computer Science student in Grade 12 at Al Noor International School in Bahrain. It includes a bonafide certificate signed by the teacher to verify the work was completed under their supervision. The record contains 12 programs written in Python covering topics like string manipulation, lists, functions, and file handling.

Uploaded by

comppract
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)
46 views18 pages

Compuooter

The document contains a lab record submission for a Computer Science student in Grade 12 at Al Noor International School in Bahrain. It includes a bonafide certificate signed by the teacher to verify the work was completed under their supervision. The record contains 12 programs written in Python covering topics like string manipulation, lists, functions, and file handling.

Uploaded by

comppract
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/ 18

AL NOOR INTERNATIONAL SCHOOL

BAHRAIN
AISSCE (2023-24)

Subject Name: COMPUTER SCIENCE


Submitted
by:
LAB RECORD
Name:
Grade: 12 A/B
Reg. no/Roll No:
Subject Code: 083
Submitted to: Ms. Fouzia Salma
DATE:
AL NOOR INTERNATIONAL SCHOOL, BAHRAIN

CBSE (2023-2024)

BONAFIDE CERTIFICATE
This is to certify that the record work done by

Mr./Miss ______________________________________ of class GRADE 12 Roll

number_____________________________ during the year 2023-2024 is

carried out under my supervision and guidance.

Teacher’s signature

AL NOOR INTERNATIONAL SCHOOL

BAHRAIN

Submitted for ALL INDIA SENIOR SCHOOL CERTIFICATE PRACTICAL

examination held on ____________________________ at

AL NOOR INTERNATIONAL SCHOOL, KINGDOM OF BAHRAIN.

Internal Examiner External Examiner


Date: __________ SIGNATURE OF THE HEAD TEACHER

PYTHON
PROGRAMMING
Program 1
Write a program that reads a string from the keyboard and displays:
*The number of uppercase letters in the string
*The number of lowercase letters in the string
*The number of digits in the string
*The number of whitespace characters in the string

Source Code
str1 = input("Enter the string: ")
lower = upper = digit = space = 0
for ch in str1:
if ch.isupper():
upper += 1
elif ch.islower():
lower += 1
elif ch.isdigit():
digit += 1
elif ch == ' ':
space += 1
print('The number of uppercase letters:', upper)
print('The number of lowercase letters:', lower)
print('The number of digits:', digit)
print('The number of whitespace characters:', space)

Output

Program 2
Write a Python program that accepts a string from user. Your program should create a new string by
shifting one position to left. For example, if the user enters the string “examination 2023” then new
string would be “xamination 2023e”

Source Code

str1=input("Enter a string: ")


newtext =str1[1:-1]+str1[-1]+str1[0]
print("New string:", newtext)

Output

Program 3
Write a program in python that accepts a string to setup a password.
Your entered password must meet the following requirements:
● The password must be at least eight characters long.
● It must contain at least one uppercase letter.
● It must contain at least one lowercase letter.
● It must contain at least one numeric digit.
● Your program should perform this validation

Source

lenght= lower = upper = digit = False


pass1=input('Enter the password: ')
if len(pass1)>= 8:
lenght = True
for letter in pass1:
if letter.islower():
lower = True
elif letter.isupper():
upper = True
elif letter.isdigit():
digit = True
if lenght and lower and upper and digit==True:
print('That is a valid password.')
else:
print('That password is invalid.')

Output

Program 4
Write a program that rotates the element of a list so that the element at the first index moves to the
second index, the element in the second index moves to the third index, etc., and the element in the last
index moves to the first index.
Source Code

list1=[]
size=int(input('How many elements you want to enter? '))
for i in range(size):
data = input()
list1.append(data)
temp = list1[size-1]
for i in range(size-1,0,-1):
list1[i] = list1[i-1]
list1[0] = temp
print('list after shifting', list1)

Output

Program 5
Write a program that accepts a string and change its lowercase vowels to
special character as given below:
a#
e@
i$
o%
u!

Source Code

str1= input("Enter the string:")


str2=""
for ch in str1:
if ch=='a':
str2+="#"
elif ch=='e':
str2+="@"
elif ch=='i':
str2+="$"
elif ch=='o':
str2+="%"
elif ch=='u':
str2+="!"
else:
str2+=ch
print(str2)

Output
Program 6
Write a program that keeps name and birthday in a dictionary as key-value pairs. The program should
display a menu that lets the user search for a person’s birthday, add a new name and birthday, change an
existing birthday, and delete an existing name and birthday.
Source Code

birthday={}
num= int(input("Enter the number of birthdays "))
for i in range(num):
name=input("Enter name")
date=input("Enter birthday")
birthday[name]=date
print("This is your birthday dictionary:",birthday)
search=input("Whose birthday did you forget? Enter your name to view birthday.")
if search in birthday:
print("{}'s birthday is on {}.".format(search,birthday[search]))
else:
print("Person cannot be found. Please add in dictionary.")
nameadd= input("Enter new name.")
dateadd= input("Enter new date.")
birthday[nameadd]=dateadd
print("This is your birthday dictionary:",birthday)
namechange= input("Enter name of the person with the wrong birthday.")
datechange= input("Enter the correct date.")
birthday[namechange]=datechange
print("This is your birthday dictionary:",birthday)
delete=input("No longer friends? Whose birthday do you want to delete?")
del birthday[delete]print("This is your birthday dictionary:",birthday)

Output
Program 7

Program 7
Write the definition of a function Alter(A, N) in python, which should change all the multiples of 5 in the
list to 5 and rest of the elements as 0.
Source Code

Output
def Alter(A,N):
for i in range(N):
if(A[i]%5==0):
A[i]=5
else:
A[i]=0
print("New list", A)
count=0
A=[]
elements=int(input('Enter number of elements:'))
while count<elements:
element=int(input('Enter element:'))
A.append(element)
count+=1
print('original list:',A)
N=len(A)
Alter(A,N)

Output

Program 8
Write a code in python for a function void Convert ( T, N) , which repositions all the elements of array by
shifting each of them to next position and shifting last element to first position.

Source code
def Convert (T, N):
for i in range(N):
t=T[N-1]
T[N-1]=T[i]
T[i]=t
print("LIst after conversion", T)

T=[1,2,3,4,5,6,7,8,9,0]
N=len(T)
Convert(T,N)

Output

Program 9
Create a function showEmployee() in such a way that it should accept employee name, and it’s salary
and display both, and if the salary Is missing in function call it should show it as 9000

Source Code
def showEmployee(name,salary=9000):
print("employee name",name)
print("salary of employee",salary)
n=input("enter employee name")
s=eval(input("enter employee's salary"))
showEmployee(n,s)

Output

Program 10
Write a program using a function which accept two integers as an argument and return its sum. Call this
function and print the results in main()

Source code
def main(a,b)
return a+b

a=int(input("enter no1: "))


b=int(input("enter no2: "))
print("Sum of a and b is",main(a,b))

Output

Program 11
Write a program to find sum of digits of a given number using function Digitsum( ) that takes a number
and returns its digit sum.

Source Code
def Digitsum(n):
sum = 0
for i in str(n)
sum = sum + int(i)
return sum
int1=int(input("Enter the number:"))
print(Digitsum(int1))

Output

Program 12
Write a program to create a function Div7and10( ) that takes a 10 elements numeric tuple and return the
sum of elements which are divisible by 7 and 10.

Source Code
def Div7and10():
x=[]
for i in range(10):
num=int(input("Enter the number:"))
append(num)
num1=0
for i in x:
if i%7==0 and i%10==0:
num1+=i
else:
continue
print(num1)
Div7and10()

Output

Program 13

Program 13
Write a function, is vowel that returns the value true if a given character is a vowel, and otherwise
returns false. Write another function main, in main() function accept a string from user and count
number of
vowels in that string.
Source code
def is_vowel(letter):
if letter in 'aeiouAEIOU':
return True
else:
return False

def main():
count = 0
string = input('Enter a text: ')
for ch in string:
if(is_vowel(ch)):
count += 1

print('Number of vowels are', count)

Output

Program 14
A text file named “matter.txt” contains some text, which needs to be displayed such that every next
character is separated by a symbol “#”. Write a function definition for hash display () in Python that
would
display the entire content of the file matter.txt in the desired format.
Example :If the file matter.txt has the following content stored in it :THE WORLD IS ROUND The function
hash_display() should display the following content :T#H#E# #W#O#R#L#D# #I#S# #R#O#U#N#D#

def hash_display():
file=open("matter.txt","r")
str1= file.read()
print("Original text:",str1)
print("Edited text:")
for i in str1:
print(i,end="#")
file.close()
hash_display()

Output

You might also like