0% found this document useful (0 votes)
19 views8 pages

Computer Science Project

The document outlines a Python program for a Student Roll Number Allotment System that allows users to enter student details, verify uniqueness, allot roll numbers, search for students, display summaries, and save results to a file. It includes functions for generating unique roll numbers, collecting student information, and managing duplicates. The program operates in a menu-driven format, enabling users to navigate through various functionalities.

Uploaded by

ashiarora171717
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)
19 views8 pages

Computer Science Project

The document outlines a Python program for a Student Roll Number Allotment System that allows users to enter student details, verify uniqueness, allot roll numbers, search for students, display summaries, and save results to a file. It includes functions for generating unique roll numbers, collecting student information, and managing duplicates. The program operates in a menu-driven format, enabling users to navigate through various functionalities.

Uploaded by

ashiarora171717
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

# Online Python compiler (interpreter) to run Python online.

# Write Python 3 code in this online editor and run it.


import random
import string

class StudentRollAllotment:
def __init__(self):
[Link] = []
self.roll_numbers = set()

def generate_roll_number(self):
"""Generate a unique roll number between 10-12 digits"""
while True:
# Generate random roll number between 10^9 and 10^12-1
roll_length = [Link](10, 12)
roll_number = ''.join([Link]([Link], k=roll_length))

# Ensure first digit is not 0


if roll_number[0] == '0':
roll_number = str([Link](1, 9)) + roll_number[1:]

if roll_number not in self.roll_numbers:


self.roll_numbers.add(roll_number)
return roll_number

def get_student_details(self):
"""Collect student details from user"""
print("=== Student Roll Number Allotment System ===")
print("Enter student details (type 'done' to finish):\n")

while True:
name = input("\nEnter student's full name: ").strip()
if [Link]() == 'done':
break

father_name = input("Enter father's name: ").strip()

# Validate input
if not name or not father_name:
print("Error: Both name and father's name are required!")
continue

[Link]({
'name': name,
'father_name': father_name,
'full_name': f"{name} {father_name}"
})

print(f"\nTotal students registered: {len([Link])}")

def verify_uniqueness(self):
"""Verify uniqueness based on name and father's name"""
unique_students = {}
duplicates = []

for student in [Link]:


key = (student['name'].lower(), student['father_name'].lower())
if key in unique_students:
[Link]((student, unique_students[key]))
else:
unique_students[key] = student

⚠️
if duplicates:
print("\n WARNING: Duplicate students found!")
print("Please verify the following students:")
for dup, original in duplicates:
print(f"Duplicate: {dup['name']} (Father: {dup['father_name']})")
print(f"Original: {original['name']} (Father: {original['father_name']})")
print("-" * 40)

response = input("\nRemove duplicates? (yes/no): ").lower()


if response == 'yes':
# Remove duplicates
[Link] = list(unique_students.values())
print(f"Removed duplicates. Total unique students: {len([Link])}")

return len(duplicates) == 0

def allot_roll_numbers(self):
"""Allot roll numbers in alphabetical order"""
if not [Link]:
print("No students to process!")
return

# Sort students alphabetically by name


[Link](key=lambda x: x['name'].lower())

print("\n" + "=" * 60)


print("ALLOTTING ROLL NUMBERS IN ALPHABETICAL ORDER")
print("=" * 60)

# Assign roll numbers


for i, student in enumerate([Link], 1):
roll_number = self.generate_roll_number()
student['roll_number'] = roll_number
student['order'] = i

print(f"{i:3}. {student['name']:30} | Father: {student['father_name']:20} | Roll: {roll_number}")

def save_to_file(self):
"""Save results to a text file"""
if not [Link]:
return

filename = "student_roll_numbers.txt"
with open(filename, 'w') as f:
[Link]("STUDENT ROLL NUMBER ALLOTMENT - ALPHABETICAL ORDER\n")
[Link]("=" * 70 + "\n\n")
[Link](f"{'[Link].':<6} {'Roll Number':<15} {'Student Name':<30} {'Father\'s Name':<20}\n")
[Link]("-" * 70 + "\n")

for student in [Link]:


[Link](f"{student['order']:<6} {student['roll_number']:<15} {student['name']:<30} {student['father_name']:
<20}\n")
print(f"\n✅ Results saved to '{filename}'")
def search_student(self):
"""Search for a student by name or roll number"""
while True:
print("\n=== SEARCH STUDENT ===")
print("1. Search by name")
print("2. Search by roll number")
print("3. Back to main menu")

choice = input("Enter your choice (1-3): ").strip()

if choice == '3':
break
elif choice == '1':
search_name = input("Enter student name: ").lower()
results = [s for s in [Link] if search_name in s['name'].lower()]
elif choice == '2':
search_roll = input("Enter roll number: ")
results = [s for s in [Link] if search_roll == [Link]('roll_number', '')]
else:
print("Invalid choice!")
continue

if results:
print(f"\nFound {len(results)} result(s):")
for student in results:
print(f"Name: {student['name']}")
print(f"Father: {student['father_name']}")
print(f"Roll: {[Link]('roll_number', 'Not allotted')}")
print("-" * 40)
else:
print("No students found!")

def display_summary(self):
"""Display summary statistics"""
if not [Link]:
print("No student data available!")
return

print("\n=== SUMMARY ===")


print(f"Total Students: {len([Link])}")
print(f"Roll Numbers Allotted: {sum(1 for s in [Link] if 'roll_number' in s)}")
print(f"Roll Number Length: 10-12 digits")
print("\nAlphabetical Range:")
print(f"First student: {[Link][0]['name']}")
print(f"Last student: {[Link][-1]['name']}")

def main():
system = StudentRollAllotment()

while True:
print("\n" + "=" * 60)
print("STUDENT ROLL NUMBER ALLOTMENT SYSTEM")
print("=" * 60)
print("1. Enter student details")
print("2. Verify uniqueness (check duplicates)")
print("3. Allot roll numbers (alphabetical order)")
print("4. Search student")
print("5. Display summary")
print("6. Save results to file")
print("7. Exit")

choice = input("\nEnter your choice (1-7): ").strip()

if choice == '1':
system.get_student_details()
elif choice == '2':
if [Link]:
system.verify_uniqueness()
else:
print("Please enter student details first!")
elif choice == '3':
system.allot_roll_numbers()
elif choice == '4':
if [Link]:
system.search_student()
else:
print("No student data available!")
elif choice == '5':
system.display_summary()
elif choice == '6':
if [Link]:
system.save_to_file()
else:
print("No student data to save!")
elif choice == '7':
print("\nThank you for using the system!")
break
else:
print("Invalid choice! Please try again.")

if __name__ == "__main__":
main()
import random
import string

class StudentRollAllotment:
def __init__(self):
[Link] = []
self.roll_numbers = set()

def generate_roll_number(self):
"""Generate a unique roll number between 10-12 digits"""
while True:
# Generate random roll number between 10^9 and 10^12-1
roll_length = [Link](10, 12)
roll_number = ''.join([Link]([Link], k=roll_length))

# Ensure first digit is not 0


if roll_number[0] == '0':
roll_number = str([Link](1, 9)) + roll_number[1:]

if roll_number not in self.roll_numbers:


self.roll_numbers.add(roll_number)
return roll_number

def get_student_details(self):
"""Collect student details from user"""
print("=== Student Roll Number Allotment System ===")
print("Enter student details (type 'done' to finish):\n")

while True:
name = input("\nEnter student's full name: ").strip()
if [Link]() == 'done':
break

father_name = input("Enter father's name: ").strip()

# Validate input
if not name or not father_name:
print("Error: Both name and father's name are required!")
continue

[Link]({
'name': name,
'father_name': father_name,
'full_name': f"{name} {father_name}"
})

print(f"\nTotal students registered: {len([Link])}")

def verify_uniqueness(self):
"""Verify uniqueness based on name and father's name"""
unique_students = {}
duplicates = []

for student in [Link]:


key = (student['name'].lower(), student['father_name'].lower())

if key in unique_students:
[Link]((student, unique_students[key]))
else:
unique_students[key] = student

⚠️
if duplicates:
print("\n WARNING: Duplicate students found!")
print("Please verify the following students:")
for dup, original in duplicates:
print(f"Duplicate: {dup['name']} (Father: {dup['father_name']})")
print(f"Original: {original['name']} (Father: {original['father_name']})")
print("-" * 40)

response = input("\nRemove duplicates? (yes/no): ").lower()


if response == 'yes':
# Remove duplicates
[Link] = list(unique_students.values())
print(f"Removed duplicates. Total unique students: {len([Link])}")

return len(duplicates) == 0

def allot_roll_numbers(self):
"""Allot roll numbers in alphabetical order"""
if not [Link]:
print("No students to process!")
return

# Sort students alphabetically by name


[Link](key=lambda x: x['name'].lower())

print("\n" + "=" * 60)


print("ALLOTTING ROLL NUMBERS IN ALPHABETICAL ORDER")
print("=" * 60)

# Assign roll numbers


for i, student in enumerate([Link], 1):
roll_number = self.generate_roll_number()
student['roll_number'] = roll_number
student['order'] = i

print(f"{i:3}. {student['name']:30} | Father: {student['father_name']:20} | Roll: {roll_number}")

def save_to_file(self):
"""Save results to a text file"""
if not [Link]:
return

filename = "student_roll_numbers.txt"
with open(filename, 'w') as f:
[Link]("STUDENT ROLL NUMBER ALLOTMENT - ALPHABETICAL ORDER\n")
[Link]("=" * 70 + "\n\n")
[Link](f"{'[Link].':<6} {'Roll Number':<15} {'Student Name':<30} {'Father\'s Name':<20}\n")
[Link]("-" * 70 + "\n")

for student in [Link]:


[Link](f"{student['order']:<6} {student['roll_number']:<15} {student['name']:<30} {student['father_name']:
<20}\n")

print(f"\n✅ Results saved to '{filename}'")


def search_student(self):
"""Search for a student by name or roll number"""
while True:
print("\n=== SEARCH STUDENT ===")
print("1. Search by name")
print("2. Search by roll number")
print("3. Back to main menu")

choice = input("Enter your choice (1-3): ").strip()

if choice == '3':
break
elif choice == '1':
search_name = input("Enter student name: ").lower()
results = [s for s in [Link] if search_name in s['name'].lower()]
elif choice == '2':
search_roll = input("Enter roll number: ")
results = [s for s in [Link] if search_roll == [Link]('roll_number', '')]
else:
print("Invalid choice!")
continue
if results:
print(f"\nFound {len(results)} result(s):")
for student in results:
print(f"Name: {student['name']}")
print(f"Father: {student['father_name']}")
print(f"Roll: {[Link]('roll_number', 'Not allotted')}")
print("-" * 40)
else:
print("No students found!")

def display_summary(self):
"""Display summary statistics"""
if not [Link]:
print("No student data available!")
return

print("\n=== SUMMARY ===")


print(f"Total Students: {len([Link])}")
print(f"Roll Numbers Allotted: {sum(1 for s in [Link] if 'roll_number' in s)}")
print(f"Roll Number Length: 10-12 digits")
print("\nAlphabetical Range:")
print(f"First student: {[Link][0]['name']}")
print(f"Last student: {[Link][-1]['name']}")

def main():
system = StudentRollAllotment()

while True:
print("\n" + "=" * 60)
print("STUDENT ROLL NUMBER ALLOTMENT SYSTEM")
print("=" * 60)
print("1. Enter student details")
print("2. Verify uniqueness (check duplicates)")
print("3. Allot roll numbers (alphabetical order)")
print("4. Search student")
print("5. Display summary")
print("6. Save results to file")
print("7. Exit")

choice = input("\nEnter your choice (1-7): ").strip()

if choice == '1':
system.get_student_details()
elif choice == '2':
if [Link]:
system.verify_uniqueness()
else:
print("Please enter student details first!")
elif choice == '3':
system.allot_roll_numbers()
elif choice == '4':
if [Link]:
system.search_student()
else:
print("No student data available!")
elif choice == '5':
system.display_summary()
elif choice == '6':
if [Link]:
system.save_to_file()
else:
print("No student data to save!")
elif choice == '7':
print("\nThank you for using the system!")
break
else:
print("Invalid choice! Please try again.")

if __name__ == "__main__":
main()

You might also like