Kendriya Vidyalaya No.
2
Chhindwara
Name: Uday Pawar
Class: 11th ‘A’
Roll number: 11119
Subject: Computer Science
Topic: Practicals
Submitted To: Mrs Sanjeev Kumar Soni Sir
Submitted By: Uday Pawar
Date: 17/02/2025
Signature:
Pratical
1) Multiplication table of a given number
num = int(input("Enter a number: "))
print(f"Multiplication Table of {num}:")
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
Output:
Enter a number: 5
Multiplication Table of 5:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
2) Write a programme to enter 2 digit and perform all arithmatic
operation.
num1 = int(input("Enter the first two-digit number: "))
num2 = int(input("Enter the second two-digit number: "))
addition = num1 + num2
subtraction = num1 - num2
multiplication = num1 * num2
division = num1 / num2 if num2 != 0 else "Undefined (division by zero)"
floor_division = num1 // num2 if num2 != 0 else "Undefined (division by zero)"
modulus = num1 % num2 if num2 != 0 else "Undefined (modulus by zero)"
exponentiation = num1 ** num2
print("\nArithmetic Operations:")
print(f"{num1} + {num2} = {addition}")
print(f"{num1} - {num2} = {subtraction}")
print(f"{num1} * {num2} = {multiplication}")
print(f"{num1} / {num2} = {division}")
print(f"{num1} // {num2} = {floor_division}")
print(f"{num1} % {num2} = {modulus}")
print(f"{num1} ** {num2} = {exponentiation}")
Output:
Enter the first two-digit number: 25
Enter the second two-digit number: 10
Arithmetic Operations:
25 + 10 = 35
25 - 10 = 15
25 * 10 = 250
25 / 10 = 2.5
25 // 10 = 2
25 % 10 = 5
25 ** 10 = 95367431640625
3) Write a programme to find average of 3 number
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
average = (num1 + num2 + num3) / 3
print(f"\nThe average of {num1}, {num2}, and {num3} is: {average}")
Output:
Enter the first number: 10
Enter the second number: 20
Enter the third number: 30
The average of 10.0, 20.0, and 30.0 is: 20.0
4) Write a programme for generating a marksheet
name = input("Enter Student Name: ")
roll_no = input("Enter Roll Number: ")
sub1 = float(input("Enter marks for Subject 1: "))
sub2 = float(input("Enter marks for Subject 2: "))
sub3 = float(input("Enter marks for Subject 3: "))
sub4 = float(input("Enter marks for Subject 4: "))
sub5 = float(input("Enter marks for Subject 5: "))
total_marks = sub1 + sub2 + sub3 + sub4 + sub5
average_marks = total_marks / 5
percentage = (total_marks / 500) * 100 # Assuming each subject is out of 100
if percentage >= 90:
grade = "A+"
elif percentage >= 80:
grade = "A"
elif percentage >= 70:
grade = "B"
elif percentage >= 60:
grade = "C"
elif percentage >= 50:
grade = "D"
else:
grade = "Fail"
print("\n********** Student Marksheet **********")
print(f"Name: {name}")
print(f"Roll Number: {roll_no}")
print(f"Total Marks: {total_marks} / 500")
print(f"Average Marks: {average_marks}")
print(f"Percentage: {percentage:.2f}%")
print(f"Grade: {grade}")
print("***************************************")
Output:
Enter Student Name: Rahul Sharma
Enter Roll Number: 12345
Enter marks for Subject 1: 85
Enter marks for Subject 2: 90
Enter marks for Subject 3: 78
Enter marks for Subject 4: 88
Enter marks for Subject 5: 92
********** Student Marksheet **********
Name: Rahul Sharma
Roll Number: 12345
Total Marks: 433 / 500
Average Marks: 86.6
Percentage: 86.60%
Grade: A
***************************************
5) Write a program to swap 2 number using a 3rd Variable.
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
print(f"\nBefore Swapping: num1 = {num1}, num2 = {num2}")
temp = num1
num1 = num2
num2 = temp
print(f"\nAfter Swapping: num1 = {num1}, num2 = {num2}")
Output:
Enter the first number: 10
Enter the second number: 20
Before Swapping: num1 = 10, num2 = 20
After Swapping: num1 = 20, num2 = 10
6) Program to check weather given number is even or odd.
num = int(input("Enter a number: "))
# Checking if the number is even or odd
if num % 2 == 0:
print(f"{num} is an Even number.")
else:
print(f"{num} is an Odd number.")
Output:
Enter a number: 15
15 is an Odd number.
7) Program to print sum of natural number between 1 to 7.
start = 1
end = 7
sum_natural = sum(range(start, end + 1))
print(f"The sum of natural numbers from {start} to {end} is: {sum_natural}")
Output:
The sum of natural numbers from 1 to 7 is: 28
8) Write a program to show a calculator
def calculator():
print("Simple Calculator")
print("Operations: +, -, *, /, //, %, **")
num1 = float(input("Enter the first number: "))
operator = input("Enter the operator (+, -, *, /, //, %, **): ")
num2 = float(input("Enter the second number: "))
if operator == '+':
result = num1 + num2
elif operator == '-':
result = num1 - num2
elif operator == '*':
result = num1 * num2
elif operator == '/':
result = num1 / num2 if num2 != 0 else "Undefined (division by zero)"
elif operator == '//':
result = num1 // num2 if num2 != 0 else "Undefined (division by zero)"
elif operator == '%':
result = num1 % num2 if num2 != 0 else "Undefined (modulus by zero)"
elif operator == '**':
result = num1 ** num2
else:
result = "Invalid operator"
print(f"Result: {result}")
calculator()
Output:
Simple Calculator
Operations: +, -, *, /, //, %, **
Enter the first number: 10
Enter the operator (+, -, *, /, //, %, **): *
Enter the second number: 5
Result: 50.0
9) Write a program to show pyramid star pattern.
rows = int(input("Enter the number of rows: "))
for i in range(1, rows + 1):
print(" " * (rows - i) + "* " * i)
output:
*
**
***
****
*****
10) Write a program to check weather the entered year is leap year or not.
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a Leap Year.")
else:
print(f"{year} is NOT a Leap Year.")
Output:
Enter a year: 2024
2024 a Leap Year.
11) Write a program to input 2 integers x and n, compute xn
using a loop.
x = int(input("Enter the base (x): "))
n = int(input("Enter the exponent (n): "))
result = 1
for i in range(n):
result *= x # Multiply x, n times
print(f"{x}^{n} = {result}")
Output:
Enter the base (x): 2
Enter the exponent (n): 5
2^5 = 32
12) Write a Program to read roll number and mark of 4 students
and create a dictionary from it having roll number as key.
student_data = {}
for i in range(4):
roll_no = input(f"Enter Roll Number of Student {i+1}: ")
marks = float(input(f"Enter Marks of Student {i+1}: "))
student_data[roll_no] = marks # Storing roll number as key and marks as value
print("\nStudent Data (Roll Number -> Marks):")
print(student_data)
Output:
Enter Roll Number of Student 1: 101
Enter Marks of Student 1: 85.5
Enter Roll Number of Student 2: 102
Enter Marks of Student 2: 78
Enter Roll Number of Student 3: 103
Enter Marks of Student 3: 90
Enter Roll Number of Student 4: 104
Enter Marks of Student 4: 88
Student Data (Roll Number -> Marks):
{'101': 85.5, '102': 78.0, '103': 90.0, '104': 88.0}
13) Write a program that creates a tupple storing 1 st nine term of
fib series
def fibonacci(n):
fib_series = [0, 1] # Initial two terms
for _ in range(n - 2): # Generate remaining terms
fib_series.append(fib_series[-1] + fib_series[-2])
return tuple(fib_series) # Convert list to tuple
fib_tuple = fibonacci(9)
print("Fibonacci Tuple:", fib_tuple)
Output:
Fibonacci Tuple: (0, 1, 1, 2, 3, 5, 8, 13, 21)
14) Write a program to create a tuple with a single input value.
# Taking input from the user
value = input("Enter a value: ")
# Creating a tuple with a single element (comma is necessary)
single_value_tuple = (value,)
# Displaying the tuple
print("Tuple with single value:", single_value_tuple)
Output:
Enter a value: 10
Tuple with single value: ('10',)
15) Write a program to find the largest/smallest number in a list/tuple.
def find_largest_smallest(sequence):
largest = max(sequence)
smallest = min(sequence)
return largest, smallest
numbers = list(map(int, input("Enter numbers separated by space: ").split()))
numbers_tuple = tuple(numbers)
largest_list, smallest_list = find_largest_smallest(numbers)
largest_tuple, smallest_tuple = find_largest_smallest(numbers_tuple)
print("\nFor List:", numbers)
print(f"Largest: {largest_list}, Smallest: {smallest_list}")
print("\nFor Tuple:", numbers_tuple)
print(f"Largest: {largest_tuple}, Smallest: {smallest_tuple}")
Output:
Enter numbers separated by space: 5 8 2 9 1 7
For List: [5, 8, 2, 9, 1, 7]
Largest: 9, Smallest: 1
For Tuple: (5, 8, 2, 9, 1, 7)
Largest: 9, Smallest: 1