Maintain student details
Maintain student details like rno, name, and per.
Defining Main Functions in Python
Many programming languages have a special function that is automatically executed when an operating system starts to run a program. This function is usually called main() and must have a specific return type and arguments according to the language standard. On the other hand, the Python interpreter executes scripts starting at the top of the file, and there is no specific function that Python automatically executes.
Nevertheless, having a defined starting point for the execution of a program is useful for understanding how a program works. Python programmers have come up with several conventions to define this starting point.
Create a Function Called main() to Contain the Code You Want to Run
Now you are able to write Python code that can be run from the command line as a script and imported without unwanted side effects. Next, you are going to learn about how to write your code to make it easy for other Python programmers to follow what you mean.
Many languages, such as C, C++, Java, and several others, define a special function that must be called main() that the operating system automatically calls when it executes the compiled program. This function is often called the entry point because it is where execution enters the program.
By contrast, Python does not have a special function that serves as the entry point to a script. You can actually give the entry point function in a Python script any name you want!
Although Python does not assign any significance to a function named main(), the best practice is to name the entry point function main() anyways. That way, any other programmers who read your script immediately know that this function is the starting point of the code that accomplishes the primary task of the script.
In addition, main() should contain any code that you want to run when the Python interpreter executes the file. This is better than putting the code directly into the conditional block because a user can reuse main()if they import your module.
Operations
1. Add at start
2. Add at end
3. Add at a position
4. Display All
5. Delete 1st element
6. Delete last element
7. Delete by position
8. Delete all elements
9. search record by roll number
10. Search record by name
#list #to maintain student details like roll,name and per #Create a Empty list import os student=[] #add aty start def addatstart(): roll=input("Enter roll no ") name=input("Enter name no ") per=input("Enter per no ") std=(roll,name,per) if(len(student)==0): student.append(std) else: student.insert(0,std) def addatend(): roll=input("Enter roll no ") name=input("Enter name no ") per=input("Enter per no ") std=(roll,name,per) student.append(std) def addatposition(): roll=input("Enter roll no ") name=input("Enter name no ") per=input("Enter per no ") std=(roll,name,per) pos=int(input("Enter the position ")) student.insert(pos-1,std) def display_all(): if(student==[]): print("List is empty") else: print("List is 1st method\n") for i in student: print(i) print("\nList is 2nd method\n") i=0 while(i<len(student)): print("roll ",student[i][0],student[i][1],student[i][2]) i=i+1 def del_first(): if(student==[]): print("List is empty") else: print("Deleted 1st element is ",student[0]) student.pop(0) def del_last(): if(student==[]): print("List is empty") else: print("Deleted Last element is ",student.pop()) def del_at_position(): pos=int(input("Enter the position ")) if not (pos<=0 or pos>len(student)): if(student==[]): print("List is empty") else: print("Deleted element is ",student.pop(pos-1)) else: print("Invalid position") def delete_all(): student.clear() def search_roll(): z=0 r=input("Enter roll to search ") if(student==[]): print("student List is empty") else: i=0 while(i<len(student)): if(student[i][0]==r): print("Record Found , Details are") z=1 print("roll ",student[i][0],student[i][1],student[i][2]) i=i+1 if z==0: print("Record with roll no ",r," is not present") def search_name(): z=0 n=input("Enter Name to search ") if(student==[]): print("student List is empty") else: i=0 while(i<len(student)): if(student[i][1]==n): print("Record Found , Details are") z=1 print("roll ",student[i][0],student[i][1],student[i][2]) i=i+1 if z==0: print("Record with Name ",n," is not present") def main(): while True: os.system("cls") print("\n\n\n1. Add at start ") print("2. Add at end ") print("3. Add at a position ") print("4. Display All") print("5. Delete 1st element ") print("6. Delete last element ") print("7. Delete by position ") print("8. Delete all elements ") print("9. search By roll ") print("10. search By Name") print("0. Exit") ch=int(input("Enter your choice ")) if(ch==1): addatstart() elif(ch==2): addatend() elif(ch==3): addatposition() elif(ch==4): display_all() elif(ch==5): del_first() elif(ch==6): del_last() elif(ch==7): del_at_position() elif(ch==8): delete_all() elif(ch==9): search_roll() elif(ch==10): search_name() elif(ch==0): break else: print("Invalid choice ") input("Press Enter to cont ...") if __name__ == "__main__": main()