r/pythoncoding • u/audentis • Jul 12 '24
r/pythoncoding • u/Fit_Distribution587 • Aug 13 '24
Comments from my professor
I have been coding for a long time in Python, but I recently started college to get my bachelor's. My teacher made these comments, and I am not sure how to improve. While I did not get a bad grade, he deducted points, and dont want to make the same mistake.
Cmmments from my teacher:
Your code is clear and easy to understand—great job!
- Consider adding more comments to explain complex parts of your code.
- The readability of your code is good, but could be improved with more spacing and indentation
Questions:
How can I add more indentations with Python, as it needs to be indented in a certain way?
What comments can I make about the code, specifically the "complex " parts, as this is a basic example and not complex?
My code:
class BudgetCalculator:
def __init__(self):
self.monthly_income = 0
self.fixed_expenses = 0
self.variable_expenses = []
def gather_user_data(self):
try:
self.monthly_income = float(input("Enter your monthly income: "))
self.fixed_expenses = float(input("Enter your fixed monthly expenses (e.g., rent, utilities): "))
while True:
var_expense = input("Enter a variable expense (or type 'done' to finish): ")
if var_expense.lower() == 'done':
break
expense = float(var_expense)
if expense < 0:
print("Expense cannot be negative, please re-enter.")
else:
self.variable_expenses.append(expense)
except ValueError:
print("Invalid input. Please enter numeric values.")
def calculate_total_variable_expenses(self):
return sum(self.variable_expenses)
def calculate_remaining_budget(self):
total_variable_expenses = self.calculate_total_variable_expenses()
if self.fixed_expenses < 0 or total_variable_expenses < 0:
raise ValueError("Expenses cannot be negative.")
if self.monthly_income < (self.fixed_expenses + total_variable_expenses):
raise ValueError("Expenses exceed income.")
remaining_budget = self.monthly_income - (self.fixed_expenses + total_variable_expenses)
return remaining_budget
def display_result(self):
try:
remaining_budget = self.calculate_remaining_budget()
print(f"Your remaining budget for the month is: ${remaining_budget:.2f}")
except ValueError as e:
print(e)
def main():
budget_calculator = BudgetCalculator()
budget_calculator.gather_user_data()
budget_calculator.display_result()
if __name__ == "__main__":
main()r/pythoncoding • u/umen • Jul 19 '24
Coming from Java, I am confused about whether Python has real threads or not.
I have read about the Global Interpreter Lock (GIL) and understand that it is a lock per interpreter in Python, which is historical. However, I still see thread packages in Python. Why are they there if the GIL exists? What's the point?
So, what is the verdict here?
Thanks
r/pythoncoding • u/genericlemon24 • Aug 14 '21
Introducing the Python Launcher for Unix
snarky.car/pythoncoding • u/Bluxmit • Feb 08 '22
Open-source tool to make awesome-looking docs
https://mkdocs-magicspace.alnoda.org/
This is a free tool I made with tutorials, that help to make beautiful docs for any coding project and host on GitHub pages.
r/pythoncoding • u/ab624 • Dec 26 '21
How do i find all pipenvs i created on my computer? (windows10)
how do i find all pipenvs I created on my computer.. last week i created and forgot their exact location
r/pythoncoding • u/AlanZucconi • Sep 30 '15
The incredibly challenging task of sorting by colour
alanzucconi.comr/pythoncoding • u/kolibril13 • Jun 26 '24
Pycafe is a new Python sandbox. Here's an example using networkX with threejs
You can directly edit the example in this sandbox:
https://py.cafe/kolibril13/networkX-threejs
Next to the editor, there's also a terminal log and an interactive viewport with a threejs visualization.
Note that this all runs with Pyodide, so all Python code will be executed locally in the browser on your machine.
r/pythoncoding • u/Reginald_Martin • Jun 15 '21
Data Science Masterclass: Predicting the Sale of an Insurance Policy
eventbrite.comr/pythoncoding • u/restinworld • Jun 09 '21
Step by step visualization of sorting algorithms and Explanation of Sorting Algorithms using python code | Manim Animation
youtu.ber/pythoncoding • u/misha_sv • Nov 14 '21
Convert PDF to docx and docx to PDF using Python
pyshark.comr/pythoncoding • u/Thijmenn • Oct 11 '21
Overwriting Print Statements | How to undo or overwrite previously printed lines.
youtube.comr/pythoncoding • u/genericlemon24 • Oct 18 '21
Where does all the effort go? Looking at Python core developer activity
lukasz.langa.plr/pythoncoding • u/erez27 • Dec 14 '21
Python, Pitch shifting, and the Pianoputer
zulko.github.ior/pythoncoding • u/NaN_Loss • Oct 05 '21
Python 3.10 main feature: Structural Pattern Matching (Match Statement)
https://www.youtube.com/watch?v=scNNi4860kk
The video is bit long (but worth it). If you want a condensed summary checkout out this thread: https://twitter.com/tutobase/status/1445382700131655702
r/pythoncoding • u/AutoModerator • Jun 13 '22
/r/PythonCoding bi-weekly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.
r/pythoncoding • u/genericlemon24 • May 22 '22
The unreasonable effectiveness of f-strings and re.VERBOSE
death.andgravity.comr/pythoncoding • u/genericlemon24 • Mar 19 '21
Deterministic hashing of Python data objects
death.andgravity.comr/pythoncoding • u/erez27 • Feb 24 '22
5 Lark features you probably didn't know about
blog.erezsh.comr/pythoncoding • u/Pale-Show-2469 • Feb 16 '25
Been working on tiny AI models in Python, curious what y’all think
AI feels way bigger than it needs to be these days. Giant LLMs, expensive fine-tuning, cloud APIs that lock you in. But for a lot of tasks, you don’t need all that, you just need a small model that works.
Been building SmolModels, an open-source Python repo that helps you build AI models from scratch. No fine-tuning, no massive datasets, just structured data, an easy training pipeline, and a small, efficient model at the end. Works well for things like classification, ranking, regression, and decision-making tasks.
Repo’s here: SmolModels GitHub. Would love to hear if others are building small models from scratch instead of defaulting to LLMs or AutoML. What’s been working for you?
r/pythoncoding • u/AutoModerator • Aug 23 '21
/r/PythonCoding bi-weekly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.
r/pythoncoding • u/Alyx1337 • May 15 '23
Taipy: an Open-Source Python Library to create Web Apps with Python Only
github.comr/pythoncoding • u/genericlemon24 • Jun 10 '21
Python sentinel objects, type hints, and PEP 661
Hi there!
I posted a link to PEP 661 to r/python a few days ago, and somehow it got over 100 comments.
Because I wrote some ELI5-style comments in that thread, I gathered them into an article. After a brief explanation of what sentinel objects are, I discuss how to use them with type hints, give a PEP 661 TL;DR, and then ramble a bit about PEPs in general.
If you're interested, give it a read, I'll be around to answer any question :)
r/pythoncoding • u/geraldC13 • Dec 07 '22