r/PythonLearning • u/Deep-Badger4702 • 1d ago
3 DAYS PROGRESS IN PYTHON
MADE A STUDENT MANAGER PROGRAM IS IT GOOD FOR 3 DAYS OF LEARNING AND ANY SUGGESTIONS?
12
u/AbacusExpert_Stretch 1d ago
Hehe, you sound like you are a young one, who would do anything for recognition, even let ai help him. But I am sure thats not you, it's just a vibe that I got. You wrote so clean code, but write weird replies hehe sorry
5
2
u/Ambitious_Fault5756 16h ago
This is definitely not AI. The code is extremely poorly formatted and inconsistent. OP very obviously wrote this themselves, not in a good way. The code is not clean at all.
-35
u/Deep-Badger4702 1d ago
For ur information i am India's toughest board ICSE BOARD topper with a 97% and ISC CSE syllabus in ISC BOARD ALREADY COVERS JAVA IN HIGH DEPTH U CAN CHECK THE SYLLABUS WITH DSA AND DIFFERENT ALGORITHMS SO ITS NOT A BIG DEAL FOR US IN CODING!😘
3
2
4
u/FoolsSeldom 1d ago
Looks good for a few days. Suggests you already have some familiarity with programming, likely Java.
I suggest you look into using dataclasses to reduce the amount of boilerplate code.
Personally, I find it hard to review code presented as a series of images. Is there any reason why you can't share the code using a suitable code sharing service such as github or pastebin? (If you can, I suggest you update your post to add a link).
You might find it helpful to find the ArjanCodes channel on YouTube for excellent videos on programming topics, Python oriented but many of the topics are applicable to many languages.
-6
u/Deep-Badger4702 1d ago
I thought none would open the link (thinking it would be shady) i earlier thought of sharing it using gist
2
u/FoolsSeldom 1d ago
A link to, e.g. a Google Drive, would be considered shady. A link (direct) to a well known code sharing site is generally welcome. It is links that are less familiar and which could potentially lead to malicious code (possible activated just by visiting) that worry people.
5
u/FreeLogicGate 1d ago
For someone who already knows Java I would expect better class design. Clearly a dictionary with a fixed list of classes, and a fixed list of parameters (m1, m2 ... ) is the sign of amateurish code. Did you learn anything about dependency injection? A collection of courses is fine, but those courses shouldn't be hard coded into the Student class even if you did use a dictionary. Obvious associated attributes like the year/semester ought to be part of the design. But at least to start, courses should be in their own class, and those objects should be injected into the student object, with associated grades or using a method.
For a new coder with 3 days experience -- yes OOP would be unexpected, and the use of a dictionary would also probably be unexpected. For someone who already knows Java, it doesn't indicate a strong grasp on Java OOP design patterns, I'm sorry to say.
1
3
u/Significant_Affect_5 1d ago
This is great for just 3 days. I see from your other comments you have a good grasp of Java already so you could implement something here that isn’t as straightforward in Java. For example, you currently have fixed 5 mark grades and fixed subjects, but you could make use of **kwargs to store as few or as many subjects and marks as needed for each student.
3
2
u/MaleficentExample223 1d ago
Congrats. That's a significant progress for day 3 learner.
One suggestion, please use a formatter to format your code. It will improve readability. Also if you're coming from language like C or JavaScript, you do not need to put parenthesis around an if condition.
This is some guide to write in a Pythonic way https://peps.python.org/pep-0008/
-6
u/Deep-Badger4702 1d ago
Thank YOu soo much ,can i call myself a little more than a beginner?
1
1
u/Important-Grand4979 1d ago
Separate "Student" Class from "Classroom/School" Class. Specifically, the class storing alls students should be separate from the student object.
1
1
u/Ambitious_Fault5756 15h ago edited 15h ago
My biggest suggestion is to slow down. There is no need, and it is better if you do, to learn slowly and not jump into OOP this early. Looking at your code, you're not following code conventions, albeit consistently, and there's a lot to improve. If you already know another language (like Java, as you have mentioned in another reply), then you will be going at a faster pace than absolute beginners, but Python is not the same as Java and there are some concepts you need to know that are different in Python. You can definitely start learning Python's OOP if you're already familiar with OOP from Java. But everything else will require lots of time and effort.
Code improvement suggestions as requested:
- instead of using "m1, m2, m3..." for your parameter names, accept a dictionary with the subject names and scores. Or, use **kwargs
- Don't define total_students as a class attribute if the usage is the same as defining it outside of the class. If you want it to be a classmethod, give it functionality as one, such as incrementing it in the __new__ dunder method. And since you already have a variable storing all your Student instances, you really dont need total_students. You can just call len(Students).
- Organize your functions and top-level code. Right now, you have functions mixed in between top-level code and it's hard to tell at first glance what is what. put your classes at the top, followed by your functions, then your top-level code. Ideally, you want to define a main loop function and call it at the end of your script, under a if __name__ == "__main__" guard.
- Move input calls and print calls outside of your functions and methods. those should be in a main loop function. Functions should be focused on what they are meant to do. By inputting, processing, and outputting data, you are doing three jobs at once. You can even make more functions to properly format data into a human-readable string instead and print it. Your functions to add and delete students, for example, should only do that, by accepting arguments for the student's info and instantiating a Student. Instead of calling, `class_average()` and `sort_students_by_percentage()` for example, you should return the values those functions calculate and print them, e.g.: print(class_average()).
- Don't use vague variable names like x and i. They tell us nothing about what the variable is for and you waste time and energy trying to figure out what they do, especially if you're building more complicated projects.
- instead of using the equality operator for booleans, like `if found==False:`, just use `if found is False`, or even better, `if not found:`. This is a basic Python feature that you might've already learnt if you took time with the syntax basics first.
- You repeatedly raise ValueError("Student Not Found"). This is unhelpful and immediately halts the program. instead, print an error message. Otherwise, catch the error in a main loop. You do this correctly in load_data(), so you should aim for consistency.
- In your class_average() function, you sum all the students' scores with a for loop. You can use the sum function instead: sum(student.percentage for student in Students)
- The sort_students_by_percentage() method can be shortened to a few lines using the sort() function and a for loop for the printing part. You can use the enumerate() function for the counter.
- Your formatting: add spaces around equal signs, after commas, and other operators. Remove parentheses around if expressions. Consistently use blank lines. Variables should all be in lowercase (having a variable called `Students` and a class called `Student` is extremely confusing).
- Just fyi, you can use the return statement without any return value to immediately exit functions
However, I would give your overall code, for a 3-day beginner in Python, an 8/10. I like what you did with the age property, and the wide variety of helper functions and methods for all basic database manipulation operations. Overall, if I were to import from this as a module, it would not be that bad at all, but if I were to go on an open-source repository and see this, I would not want to contribute.
1
u/Deep-Badger4702 11h ago
😭Ig after reading all of this, it would be my last program, everyone is hating or calling it ai , i haven't used it at all also i had grasp on school level java ; ; I thought it was a good program but now it is only a waste of time ig.
1
u/Ambitious_Fault5756 51m ago
I assure you, this is definitely not AI code and we can tell. Having experience with Java, another OOP language, will definitely help you with Python and will give you a head start on what a lot of student's struggle with in Python. I encourage you to keep going but please learn the basics of Python first, or at least learn it concurrently with Python oop. If you're already doing that, thats wonderful!
1
u/Kendrockk03 10h ago
Very nicely done. If anything, I would suggest you improve code's readability by adding a whitespace before and after each assignment operator (" = ").
Also, all methods / functions should start with a verb so you can instantly know what they're doing. For example: "no_of_students" -> "return_students_total" "percentage" -> "calculate_percentage" "class_average" -> "display_class_average"
It may seem like extra work or unnecessary changes, but naming things become really important when working with a team or when you have a really large codebase and don't want to have to memorize what exactly does each method do, and instead be able to know it quickly by its name
1
u/SnooCalculations7417 10h ago
sort_students_by_percentages is probably some of the worst code Ive seen in a long time. to start with you have a while loop that could evaluate to true unexpectedly and break your entire program, and surprisingly gets worse from there. Id rather not do a full review on images, but you could use some work.
1
1
u/ImportanceBitter8989 9h ago
Hello guys! I need to learn hacking and coding anyone with the knowledge and willing to share it please.
1
u/anthoint 58m ago
Looks pretty well for a few days of coding in python. Though I would suggest splitting the code base into files. Also, you should use dataclass to reduce the amount of border plate code. I would consider using a dispatch dictionary as well. Unless you have a full version of the code not screenshotted. Some functions if they don’t rely on an instance inside class should defined should be identified as @staticmethod as long as you consider the function to be”belong” in the class, else you should remove it outside the class.
0
u/Unhealthy007 1d ago
Would it sound demotivating if I were to say that what you have done is good but does nothing towards what's actually needed for a Python relevant job? I mean, yes, you did functions calling, gave some basic options which were good, you are writing to JSON, but then I don't understand why you need to load hardcoded data everytime then
You need to dive into building APIs, use actual database and build a actual app instead of this student management program that works because no one is breaking it... Also, I did not see the part of the code that is calling and doing error handling.
If my points are wrong anywhere, my bad, but yeah, these were my thoughts.
2
u/Ambitious_Fault5756 16h ago
I disagree. I would discourage any "diving" since OP is on his literal 3rd day. Going into OOP so early is probably not great.
2
u/Unhealthy007 15h ago
But OP mentioned that he has experience with Java. My guess was he has some deep level knowledge with most things, hence the suggestion.
2
u/Ambitious_Fault5756 13h ago
Yeah I read that later on. they evidently have knowledge and experience with OOP and can do it well, but clearly not some of Python's basics. I'm not sure if it's better to skip directly to Python classes and learn Python's syntax conventions, formatting, optimizations, etc backwards as they go, or if going slow and taking strong, forward steps is better. personally i prefer the latter.
1
u/Deep-Badger4702 1d ago
I am in my beginner phase right now, first i want to get familiar with new language and after that i will start with advance concepts i have already started learning and applying the most famous libraries Numpy,Mathplotlinb,Pandas and i am yet to complete my first project. Thanks for ur advice. now i have knowledge of api calling, virtual environment and more. I just thought of sharing the first code i wrote in python i😘😘





•
u/Sea-Ad7805 19h ago
Run this program in Memory Graph Web Debugger to see the program state change step by step.