0% found this document useful (0 votes)
5 views5 pages

Computer Science Practical Exercises

The document is a practical file for a Computer Science course, detailing various programming exercises for the session 2025-26. It includes tasks such as sorting numbers, checking for palindromes, generating prime numbers, and calculating Fibonacci series, along with their corresponding Python code and example outputs. Each program addresses fundamental programming concepts and provides hands-on practice for students.

Uploaded by

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

Computer Science Practical Exercises

The document is a practical file for a Computer Science course, detailing various programming exercises for the session 2025-26. It includes tasks such as sorting numbers, checking for palindromes, generating prime numbers, and calculating Fibonacci series, along with their corresponding Python code and example outputs. Each program addresses fundamental programming concepts and provides hands-on practice for students.

Uploaded by

kalpanapriyam213
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Science Practical File (083)

Prepared by: Student


Subject: Computer Science
Session: 2025-26

Table of Contents
SL No. Content Page No.
1 Sort 3 numbers in descending order using conditional statement 2
2 Check if input number is palindrome or not 3
3 Search for prime numbers from 10 to 30 4
4 Display Fibonacci series (first 20 numbers) 5
5 Read two numbers and operator, display result 6
6 Calculate and print roots of quadratic equation 7
7 Find sum of series 1+x^2/2+x^3/3+...+x^n/n 8
8 Pattern printing 9
9 Input string and count upper, lower, digits, symbols 10
10 Capitalize first letter of each word in string 11
11 Check palindrome string without using slice 12

Program 1: Sort 3 numbers in descending order


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
if b >= c:
print(a, b, c)
else:
print(a, c, b)
elif b >= a and b >= c:
if a >= c:
print(b, a, c)
else:
print(b, c, a)
else:
if a >= b:
print(c, a, b)
else:
print(c, b, a)

Output:
Output:
Enter first number: 5
Enter second number: 2
Enter third number: 8
8 5 2

Program 2: Check palindrome number


num = int(input("Enter a number: "))
temp = num
rev = 0
while num > 0:
rev = rev * 10 + num % 10
num //= 10
if temp == rev:
print("Palindrome number")
else:
print("Not a palindrome")

Output:
Output:
Enter a number: 121
Palindrome number

Program 3: Prime numbers from 10 to 30


for num in range(10, 31):
for i in range(2, num):
if num % i == 0:
break
else:
print(num, end=' ')

Output:
Output:
11 13 17 19 23 29

Program 4: Fibonacci series (first 20 numbers)


a, b = 0, 1
for i in range(20):
print(a, end=' ')
a, b = b, a + b

Output:
Output:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
Program 5: Read two numbers and operator
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
op = input("Enter operator (+, -, *, /): ")
if op == '+':
print(a + b)
elif op == '-':
print(a - b)
elif op == '*':
print(a * b)
elif op == '/':
print(a / b)
else:
print("Invalid operator")

Output:
Output:
Enter first number: 8
Enter second number: 4
Enter operator: *
32

Program 6: Roots of quadratic equation


import math
a = float(input("Enter a: "))
b = float(input("Enter b: "))
c = float(input("Enter c: "))
d = b**2 - 4*a*c
if d > 0:
r1 = (-b + [Link](d)) / (2*a)
r2 = (-b - [Link](d)) / (2*a)
print("Roots are real and different:", r1, r2)
elif d == 0:
print("Roots are real and equal:", -b / (2*a))
else:
print("Roots are imaginary")

Output:
Output:
Enter a: 1
Enter b: 4
Enter c: 4
Roots are real and equal: -2.0

Program 7: Sum of series 1+x^2/2+x^3/3+...+x^n/n


x = int(input("Enter value of x: "))
n = int(input("Enter value of n: "))
sum_series = 0
for i in range(1, n+1):
sum_series += x**i / i
print("Sum of series:", sum_series)

Output:
Output:
Enter value of x: 2
Enter value of n: 3
Sum of series: 9.333333333333334

Program 8: Pattern printing


for i in range(1, 6):
for j in range(1, i+1):
print(j, end=' ')
print()

Output:
Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Program 9: String analysis


s = input("Enter a string: ")
upper = lower = digit = symbol = 0
for ch in s:
if [Link]():
upper += 1
elif [Link]():
lower += 1
elif [Link]():
digit += 1
else:
symbol += 1
print("Upper:", upper, "Lower:", lower, "Digits:", digit, "Symbols:", symbol)

Output:
Output:
Enter a string: Hello123!
Upper: 1 Lower: 4 Digits: 3 Symbols: 1
Program 10: Capitalize each word
s = input("Enter a sentence: ")
words = [Link]()
new_sentence = ' '.join([Link]() for word in words)
print(new_sentence)

Output:
Output:
Enter a sentence: welcome to python
Welcome To Python

Program 11: Palindrome string without slice


s = input("Enter a string: ")
rev = ""
for ch in s:
rev = ch + rev
if s == rev:
print("Palindrome string")
else:
print("Not a palindrome")

Output:
Output:
Enter a string: madam
Palindrome string

You might also like