Index
Index
Practical file
SUBMITTED BY: -
Name: S. Roshan Kumar
Class & Section: XII B
Session :2024-25
INDEX
Roots of a Quadratic Equation
1.
Currency Conversion
2.
Math Module Remake
3.
Character Counting
4.
GCD and LCM Calculator
5.
Temperature Conversions
6.
Password Strength Check
7.
Student Compare
8.
Decimal to Binary Conversion
9.
Sequence Counter
10.
Student Details Data Handling
11.
Guess a Number! Game
12.
GST Rate Calculator
13.
14. Stone, Paper, and Scissors! Game
main()
Currency Conversion
Convert between different currencies based on
current exchange rates.
conversion_rates = { "USD": {"INR": 74.5, "EUR": 0.85, "JPY":
110},"INR": {"USD": 0.013, "EUR": 0.011, "JPY": 1.47} }
def currency_conversion(amount, from_currency, to_currency):
if from_currency in conversion_rates and to_currency in
conversion_rates[from_currency]:
return amount * conversion_rates[from_currency]
[to_currency]
else:
return None
# Enhanced with user interaction
def main():
try:
amount = float(input("Enter amount: "))
from_currency = input("From currency (USD, INR, EUR, JPY):
").upper()
def custom_square_root(x):
return x ** 0.5
main()
Character Counting
Count the number of characters, words, and
sentences in a given text.
def character_count(text):
# Initialize counters
char_count = len(text)
word_count = len(text.split())
line_count = text.count('\n') + 1 if text else 0
vowel_count = sum(1 for char in text if char.lower() in
'aeiou')
consonant_count = sum(1 for char in text if char.isalpha()
and char.lower() not in 'aeiou')
digit_count = sum(1 for char in text if char.isdigit())
space_count = text.count(' ')
sentence_count = sum(text.count(punct) for punct in ['.', '!',
'?'])
# Display results
print(f"Total Characters (including spaces): {char_count}")
print(f"Total Words: {word_count}")
print(f"Total Lines: {line_count}")
print(f"Total Vowels: {vowel_count}")
print(f"Total Consonants: {consonant_count}")
print(f"Total Digits: {digit_count}")
print(f"Total Spaces: {space_count}")
print(f"Total Sentences: {sentence_count}")
# Enhanced with interactive input and error handling
def main():
print("Character Counting Program")
print("==========================")
try:
text = input("Enter your text (press Enter to end input):\
n")
if not text:
print("No input provided.")
else:
character_count(text)
except Exception as e:
print(f"An error occurred: {e}")
print("==================================
=====")
print("1. Calculate GCD")
print("2. Calculate LCM")
print("3. Calculate both GCD and LCM")
try:
choice = input("Enter your choice (1/2/3): ")
if choice not in ['1', '2', '3']:
print("Invalid choice. Please enter 1, 2, or 3.")
return
numbers = input("Enter numbers separated by spaces:
").split()
numbers = [int(num) for num in numbers]
if choice == '1':
gcd_result = calculate_gcd(numbers)
print(f"The GCD of {numbers} is: {gcd_result}")
def fahrenheit_to_celsius(f):
return (f - 32) * 5/9
def celsius_to_kelvin(c):
return c + 273.15
def kelvin_to_celsius(k):
return k - 273.15
main()
def check_password_strength(password):
length = len(password) >= 8
upper = re.search(r'[A-Z]', password)
lower = re.search(r'[a-z]', password)
digit = re.search(r'[0-9]', password)
special = re.search(r'[@$!%*?&]', password)
if length and upper and lower and digit and special:
return "Strong Password"
else:
return "Weak Password"
# Example usage:
print(check_password_strength("P@ssw0rd"))
Student compare
Compare the details (such as grades) of two or
more students.
class Student:
def __init__(self, name, math, science, english):
self.name = name
self.average = (math + science + english) / 3
def input_student():
name = input("Enter student's name: ")
math = float(input("Enter Math grade: "))
science = float(input("Enter Science grade: "))
english = float(input("Enter English grade: "))
return Student(name, math, science, english)
# Main code
print("Enter details for Student 1:")
student1 = input_student()
print("\nEnter details for Student 2:")
student2 = input_student()
compare_students(student1, student2)
Decimal to Binary
Conversion
Convert a decimal number to its binary
equivalent.
def decimal_to_binary(decimal):
"""Convert a decimal number to binary."""
if decimal < 0:
return '-' + bin(decimal)[3:] # Handling negative numbers
else:
return bin(decimal)[2:] # Convert and strip '0b' prefix
def main():
print("Decimal to Binary Converter")
print("===========================")
while True:
try:
# Take input from the user
decimal = int(input("\nEnter a decimal number (or 'q' to
quit): "))
except ValueError:
print("Please enter a valid integer or 'q' to quit.")
# Check if the user wants to continue
cont = input("Would you like to convert another number?
(y/n): ")
if cont.lower() != 'y':
print("Thank you for using the Decimal to Binary
Converter!")
break
if name in student_list:
print(f"{name} is already in the list.")
else:
student_list.append(name)
print(f"{name} has been added.")
def main():
print("Student Counter Program")
print("========================")
student_list = []
while True:
add_student(student_list)
def add_student(students):
name = input("Name: ").strip()
age = int(input("Age: "))
grade = input("Grade: ")
subjects = input("Subjects (comma-separated): ")
students[name.lower()] = Student(name, age, grade,
subjects)
def view_student(students):
name = input("Enter name to view: ").strip().lower()
print(students.get(name, "Student not found."))
def list_students(students):
for student in students.values(): print(student)
print(f"Total: {len(students)}")
students = {}
while True:
option = input("\n1. Add 2. View 3. List 4. Exit\nChoose: ")
if option == '1': add_student(students)
elif option == '2': view_student(students)
elif option == '3': list_students(students)
elif option == '4': break
def play_game():
print("Welcome to the Guess a Number Game!")
level = int(input("Choose difficulty - 1: Easy (1-10), 2:
Medium (1-50), 3: Hard (1-100): "))
range_limit, max_attempts = [(10, 5), (50, 7), (100, 10)]
[level - 1]
# Calculate GST
gst_amount, total_amount = calculate_gst(amount, gst_rate)
def pop(stack):
print(f"{stack.pop() if stack else 'Stack is empty! Cannot
pop.'}")
def peek(stack):
print(f"Top of stack: {stack[-1] if stack else 'Stack is
empty!'}")
def display(stack):
print(f"Stack contents: {stack if stack else 'Stack is
empty!'}")
def main():
stack = []
print("Stack Operations: 1.Push 2.Pop 3.Peek 4.Display
5.Exit")
while True:
choice = input("Enter choice (1-5): ")
if choice == '1':
push(stack, input("Enter item to push: "))
elif choice == '2':
pop(stack)
elif choice == '3':
peek(stack)
elif choice == '4':
display(stack)
elif choice == '5':
print("Exiting..."); break
else:
print("Invalid choice!")
main()
Employees Database
A database to store and manage employee
details, such as name, position, and salary.
def main():
employees = {}
while True:
choice = input("1.Add 2.Search 3.Delete 4.Display 5.Exit:
")
if choice == '1':
emp_id = input("ID: "); name = input("Name: "); des =
input("Designation: ")
employees[emp_id] = {'Name': name, 'Designation':
des}
elif choice == '2':
emp_id = input("Search ID: ")
print(employees.get(emp_id, "Not Found"))
elif choice == '3':
emp_id = input("Delete ID: ")
print("Deleted" if employees.pop(emp_id, None) else
"Not Found")
elif choice == '4':
for emp_id, info in employees.items():
print(f"ID: {emp_id}, Name: {info['Name']},
Designation: {info['Designation']}")
elif choice == '5': break
main()
Expense Management
System
Track and manage expenses with options to add,
view, and categorize expenses.
def add_expense(expenses):
name = input("Enter Expense Name: ")
amount = float(input("Enter Amount: "))
expenses.append({'Name': name, 'Amount': amount})
print(f"Expense '{name}' added.")
def view_expenses(expenses):
if expenses:
print("\nExpenses:")
for exp in expenses:
print(f"{exp['Name']}: ₹{exp['Amount']}")
else:
print("No expenses recorded yet.")
def main():
expenses = []
print("Expense Management System")
while True:
choice = input("1. Add Expense 2. View Expenses 3. Exit:
")
if choice == '1':
add_expense(expenses)
elif choice == '2':
view_expenses(expenses)
elif choice == '3':
print("Exiting system.")
break
else:
print("Invalid choice! Please select a valid option.")
main()
def view_students(students):
if students:
print("\nStudent List:")
for student_id, name in students.items():
print(f"ID: {student_id}, Name: {name}")
else:
print("No students recorded yet.")
def main():
students = {}
print("Student Database System")
while True:
choice = input("1. Add Student 2. View Students 3. Exit: ")
if choice == '1':
add_student(students)
elif choice == '2':
view_students(students)
elif choice == '3':
print("Exiting system.")
break
else:
print("Invalid choice! Please select a valid option.")
main()
Adding and Remove
Student Database
Add, remove, and manage student records in a
database.
def add_student(students):
student_id = input("Enter Student ID: ")
name = input("Enter Student Name: ")
students[student_id] = name
print(f"Student '{name}' added.")
def remove_student(students):
student_id = input("Enter Student ID to remove: ")
if student_id in students:
del students[student_id]
print(f"Student with ID {student_id} removed.")
else:
print(f"Student with ID {student_id} not found.")
def view_students(students):
if students:
print("\nStudent List:")
for student_id, name in students.items():
print(f"ID: {student_id}, Name: {name}")
else:
print("No students recorded yet.")
def main():
students = {}
print("Student Database Management")
while True:
choice = input("1. Add Student 2. Remove Student 3. View
Students 4. Exit: ")
if choice == '1':
add_student(students)
elif choice == '2':
remove_student(students)
elif choice == '3':
view_students(students)
elif choice == '4':
print("Exiting system.")
break
else:
print("Invalid choice! Please select a valid option.")
main()
Employee Payroll
Management System
Calculate and manage employee payroll details,
including salary, deductions, and net pay.
def add_employee(employees):
emp_id = input("Enter Employee ID: ")
name = input("Enter Employee Name: ")
salary = float(input("Enter Salary: "))
employees[emp_id] = {'Name': name, 'Salary': salary}
print(f"Employee '{name}' added.")
def view_employees(employees):
if employees:
print("\nEmployee List:")
for emp_id, details in employees.items():
print(f"ID: {emp_id}, Name: {details['Name']}, Salary: ₹
{details['Salary']}")
else:
print("No employees recorded yet.")
def update_salary(employees):
emp_id = input("Enter Employee ID to update salary: ")
if emp_id in employees:
new_salary = float(input("Enter new salary: "))
employees[emp_id]['Salary'] = new_salary
print(f"Salary updated for employee {emp_id}.")
else:
print(f"Employee with ID {emp_id} not found.")
def main():
employees = {}
print("Employee Payroll Management System")
while True:
choice = input("1. Add Employee 2. View Employees 3.
Update Salary 4. Exit: ")
if choice == '1':
add_employee(employees)
elif choice == '2':
view_employees(employees)
elif choice == '3':
update_salary(employees)
elif choice == '4':
print("Exiting system.")
break
else:
print("Invalid choice! Please select a valid option.")
main()