r/learnpython • • 13h ago

Rate my customer/employee id generation logic

4 Upvotes
def generate_id(connection_tuple, id_user = "customer"):
    if id_user.lower() == "customer":
        table = "customer"
        id_string = "cust"
    elif id_user.lower() == "employee":
        table = "employees"
        id_string = "emp"
    cursor = connection_tuple[1]
    connection = connection_tuple[0]
    try_cursor_execute(f"select count(*) form {table}")
    last_person = cursor.fetchone()[0]
    current_person = last_person+1
    no_of_zeros = 6 - len(str(current_person))
    id = id_string + "0"*no_of_zeros + str(current_perosn)
    return id

I have to build a hotel database system thing for my 12th grade Computer Science project.. This is the customer id / employee id generation logic I came up with. Employee IDs are 9 characters, and customer IDs are 10 characters. But this thing seems sort of janky. Is there a better way to do this?

try_cursor_execute() is a function I defined, it is cursor.execute but in a try block. connection tuple is (connection, cursor)


r/learnpython • • 9h ago

how to make learning python faster with AI help/assistance

0 Upvotes

guys i have been learning python through the popular book Automating stuff with python, i read through the theory and try to implement the codes and understand themselves in detail, but i feel like i am not using an optimized approach, how do i make sure i make my learning faster with the help of AI, because of all the things AI has done till now i feel like surely it has changed the way of learning a bit, does anyone have any tips and tricks?


r/learnpython • • 35m ago

I built a free portfolio risk dashboard and would appreciate feedback from people learning about investing

0 Upvotes

Hi everyone!

I'm a high school student interested in finance and programming, and I've been working on a portfolio risk dashboard as a personal project.

The goal is to help people understand how different stock allocations affect portfolio performance and risk, rather than just focusing on returns.

Right now, it lets users:

  • Build a portfolio with custom stock allocations
  • Compare historical performance against the S&P 500
  • Explore metrics like volatility, beta, Sharpe ratio, and maximum drawdown
  • Visualize stock correlations and diversification

I also added a beginner example and explanations for people who aren't familiar with these concepts.

I'm trying to improve the tool based on actual user feedback, especially from beginners.

I'd really appreciate thoughts on a few things:

  1. Are the financial metrics explained clearly enough for someone new to investing?
  2. Is there anything confusing about the interface?
  3. What would make this more useful as an educational tool?

It's completely free, and I'm not selling anything. It's intended for education, not investment advice.

Thanks to anyone willing to share feedback. I can send the link to anyone interested; I just can't add it to this post!


r/learnpython • • 5h ago

College student transitioning from MERN development to AI engineering – What should I prioritize?

0 Upvotes

I'm planning to transition towards AI engineering.

My learning plan:

  1. Python and DSA
  2. NumPy, Pandas and Mathematics
  3. Machine Learning
  4. Deep Learning
  5. LLMs, RAG and AI agents

I want to build AI-powered full-stack applications rather than just follow tutorials.

For people already working in this field:

- What foundational concepts should I master?

- Which projects demonstrate practical AI engineering skills?

- What mistakes should beginners avoid?

I'd appreciate advice from people with real implementation experience.


r/learnpython • • 2h ago

Asking your ratings for my first ever python project!

5 Upvotes

Hello, everyone!

I'm learning Python through the CS50 course. In the meantime, I built a simple weather app using the concepts I've learned so far.

I'd really appreciate it if you could take a look at my work and point out any weaknesses in my program. I'd also love to hear your suggestions for future improvements.

Thank you! 🤗

GitHub: https://github.com/bihandumethum096-droid/Weather-App


r/learnpython • • 6h ago

Can seaborn.clustermap() use dataframe that has all zero columns?

0 Upvotes

As the title suggests, can the clustermap display a dataset with multiple columns that are all zeros?

Something like this:

ABCDXY
110000
110100
110000
101000
101100
101000

I know removing the empty columns is the simple solution, but I have my reasons for keeping them.


r/learnpython • • 17h ago

Python environments question

3 Upvotes

I've been playing The Farmer was Replaced a bunch and one of the things that has helped me get into the groove has been the ability to physically move scripts around.

Are there any environments out there that do that? Where i can see multiple scripts and move them around?

feels far fetched but it would be cool


r/learnpython • • 8h ago

Remove padding of polar subplots

5 Upvotes

I have a figure that is composed of many subplots. Some of them are just simple plots with a normal projection, but some are made with a polar projection. I have it set up such that there are no labels on the outside of the polar plots, but when I look at the final figure, I still get tiny plots compared to the other ones because there is a lot of padding kept on the margins of the polar subplots. I have already tried passing the pad=0 option while plotting, as well as using plt.subplots_adjust() or plt.tight_layout(), but I still get comparatively smaller radar plots. I could fix this manually using an external editor, but I would like to be able to solve it using Python on its own.


r/learnpython • • 18h ago

how do i make an embedded lua interpreter?

3 Upvotes

im trying to make a project where in some parts you can run actual lua code. how would i make this and what libraries would i need (i already have lupa if that is usefull)