You are on page 1of 33

COMPUTER SCIENCE (083)

PRACTICALS
OR
INFORMATICS PRACTICES (065)
PRACTICALS

YEAR 2023-24

Name: _______
Roll No: ______
Class & Sec: ____
INDEX
Sr. no Name of the Practical Page No Date Signature

1 Input a welcome message and display it 1

2 Input two numbers and display 1

larger/smaller

3 Input three numbers and display the 3

largest / smallest number.

4 Generate the following patterns using nested loops: 5

5 Solve the series 7

6 Determine whether a number is a perfect number, an 9


Armstrong number or a palindrome.

7 Input a number and check if the number is a prime 13


or composite number.

8 Display the terms of a Fibonacci series. 15


9 Compute the greatest common divisor and least 16
common multiple of two integers.

10 Count and display the number of vowels, 19


consonants, uppercase, lowercase characters in
string.

11 Input a string and determine whether it is a 21


palindrome or not; convert the case of characters in
a string.

12 Find the largest/smallest number in a list/tuple 22

13 Input a list of numbers and swap elements at the 23


even location with the elements at the odd location.

14 Input a list/tuple of elements, search for a given 25


element in the list/tuple.

15 Create a dictionary with the roll number, name and 29


marks of n students in a class and display the
names of students who have marks above 75.

Practical 1
Input a welcome message and display it

Code:

welcome_message=input("Enter welcome message : ")

print("Hello, ",welcome_message)

Result:

Practical 2:

Input two numbers and display the larger / smaller number.

Code:

a=int(input("Enter a number")); b=int(input("Enter another number"));

if a>b: print("First number is greater is than second number");

elif a==b: print("First number is equal to the second number");

else:

print("First number is smaller than the second number")

Result:
Practical 3 :

Input three numbers and display the largest / smallest number.

Code:

a=int(input("Enter a number"));

b=int(input("Enter another number"));

c=int(input("Enter a third number"));

if a>b and a>c:

print("The first number is the greatest");

elif a<b and b>c:

print("The second number is the greatest");

else:

print("The third number is the greatest")

if a<b and a<c:

print("The first number is the smallest");

elif a>b and b<c:

print("The second number is the smallest");

else:

print("The third number is the smallest")

Result:
Practical 4:

Generate the following patterns using nested loops:

Code: 1

for i in range(1,6):

for j in range(i):

print(" * ", end = "")

print( )

Result:
Code: 2

for i in range(6,0,-1):

for j in range(1, i):

print(j, end = " ")

print()

Result:

Code: 3

n=5

for i in range(n):

for j in range(i+1):

print(chr(j + 65), end="")


print()

Result:

Practical: 5

Code:

#series 1

#series2
#series3

#series4
Result:

1: 2:

3: 4:

Practical: 6

#palindrome number
number=int(input("Enter any number:"))

num=number

num1= number

rev=0

while num>0:

digit=num%10

rev=rev*10+digit

num=int(num/10)

if number==rev:

print(number ,'is a Palindrome')

else:

print(number , 'Not a Palindrome')

#perfect number

number=int(input("Enter any number:"))


num=number

num1= number

rev=0

sum1 = 0

for i in range(1, number):

if(number % i == 0):

sum1 = sum1 + i

if (sum1 == number):

print(number, " The number is a Perfect number")

else:

print(number, " The number is not a Perfect number")

#armstrong number
number=int(input("Enter any number:"))

num=number

num1= number

rev=0

sum = 0

temp = num1

while temp > 0:

digit = temp % 10

sum += digit ** 3

temp //= 10

if num1 == sum:

print(num1," is an Armstrong number")

else:

print(num1," is not an Armstrong number")


Result:

1: 2:

3:

Practical: 7

input a number and check if prime or composite

Code:

#input a number and check if prime or composite

num = int(input("enter any number : "))

if num > 1:

for i in range(2, num):


if (num % i) == 0:

print(num, "is a composite number")

break

else:

print(num, "is a prime number")

elif num == 0 or 1:

print(num, "is a neither prime nor composite number")

else:

print()

Result:
Practical: 8

fibonacci series

Code:

#fibonacci series

n = int(input("Number of terms"))

n1, n2 = 0, 1

print("Fibonacci Series:", n1, n2, end=" ")

for i in range(2, n):

n3 = n1 + n2

n1 = n2

n2 = n3

print(n3, end=" ")

print()
Result:

Practical: 9

Code:

#greatest common divisor

num1 = int(input("Enter 1st number: "))

num2 = int(input("Enter 2nd number: "))

i=1

while(i <= num1 and i <= num2):

if(num1 % i == 0 and num2 % i == 0):

gcd = i
i=i+1

print("Greatest Common Divisor is ", gcd)

#least common multiple

num1 = int(input("Enter 1st number: "))

num2 = int(input("Enter 2nd number: "))

i=1

if num1 > num2:

greater = num1

else:
greater = num2

while(True):

if((greater % num1 == 0) and (greater % num2 == 0)):

lcm = greater

break

greater += 1

print("The Least Common Multiple (LCM) is ", lcm)

Result:

Practical: 10
Code:

#vowels and consonat counts

str = input("Type the string: ")

vowel_count=0

consonants_count=0

vowel = set("aeiouAEIOU")

for alphabet in str:

if alphabet in vowel:

vowel_count=vowel_count +1

elif alphabet == chr(32):

consonants_count=consonants_count

else:

consonants_count=consonants_count+1
print("Number of Vowels in ",str," is :",vowel_count)

print("Number of Consonants in ",str," is :",consonants_count)

#uppercase and lowercase count

str = input("Type the string: ")

uppercase_count=0

lowercase_count=0
for elem in str:

if elem.isupper():

uppercase_count += 1

elif elem.islower():

lowercase_count += 1

print("Number of UPPER Case in ",str," is :",uppercase_count)

print("Number of lower case in ",str," is :",lowercase_count)

Result:

Practical: 11
Code:

#To check if string is palindrome or not

str=input("Enter a string:")

w=""

for element in str[::-1]:

w = w+element

if (str==w):

print(str, 'is a Palindrome string')

else:

print(str,' is NOT a Palindrome string')


#convert case of characters into a string

str=input("Enter a string:")

w=""

for element in str[::1]:

if element.isupper():

w = w+element.lower()

else:

w = w+element.upper()

print(w)
Result:

Practical: 12

Code:

#To find smallest and largest number of a list

NumList = []

Number = int(input("Please enter the Total Number of List Elements: "))

for i in range(1, Number + 1):

value = int(input("Please enter the Value of %d Element : " %i))

NumList.append(value)
print("The Smallest Element in this List is : ", min(NumList))

print("The Largest Element in this List is : ", max(NumList))

Result:

Practical: 13

Code:

#Input a list of numbers and swap elements at the even location with the elements

at the odd location

mylist = []
print("Enter 5 elements for the list: ")

for i in range(5):

value = int(input())

mylist.append(value)

print("The original list : " + str(mylist))

odd_i = []

even_i = []

for i in range(0, len(mylist)):

if i % 2:

even_i.append(mylist[i])

else :

odd_i.append(mylist[i])

result = odd_i + even_i

print("Separated odd and even index list: " + str(result))


Result:

Practical: 14

Code:

#Input a list/tuple of elements, search for a given element in the list/tuple

mylist = []
print("Enter 5 elements for the list: ")

for i in range(5):

value = int(input())

mylist.append(value)

print("Enter an element to be search: ")

element = int(input())

for i in range(5):

if element == mylist[i]:

print("\nElement found at Index:", i)

print("Element found at Position:", i+1)

Result:
Practical: 15

Code:

#dictionary

no_of_std = int(input("Enter number of students: "))

result = {}

for i in range(no_of_std):

print("Enter Details of student No.", i+1)


roll_no = int(input("Roll No: "))

std_name = input("Student Name: ")

marks = int(input("Marks: "))

result[roll_no] = [std_name, marks]

print(result)

for student in result:

if result[student][1] > 75:

print("Student's name who get more than 75 marks is",(result[student][0]))

Result:

You might also like