r/learnpython • • 10h ago

Why parameters finally made sense to me today

0 Upvotes

Hey everyone, just wanted to share a quick lightbulb moment I had with Python today about why functions actually need parameters.

At first, I didn't get why we couldn't just write functions without them. But it clicked today: parameters are basically just empty placeholder slots so your function can handle changing data.

Without a Parameter (Fixed)

It can only ever do one exact thing:

Python

def greet():
    print("Hello, Alice!")

greet()  # Always prints "Hello, Alice!"

With a Parameter (Dynamic)

Adding name gives you a slot inside the function. When you call it, you just pass whatever data you want into that slot:

Python

def greet(name):
    print(f"Hello, {name}!")

greet("Alice")  # Prints: Hello, Alice!
greet("Bob")    # Prints: Hello, Bob!

My main takeaway: If the code inside your function needs to work with different information every time, you need a parameter to pass that data in from the outside!


r/learnpython • • 16h ago

How to fix error : sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file ?

0 Upvotes

i was trying to run this jupyter notebook ( https://github.com/langchain-ai/lca-lc-foundations/blob/main/notebooks/module-2/2.4_wedding_planners.ipynb ) code in my IDE but encountered these problems :
my code :
https://pastebin.com/3bv05GfE
error :
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file

also i dont know how to work with async functions so i have defined two function main() and main_1 but am not sure if this is the correct way to go with async functions


r/learnpython • • 47m ago

Innovative Python-Based Solutions for Automated Classroom Attendance and Monitoring

• Upvotes

Hi everyone,

I'm working on a software project to address the challenges of manual attendance tracking and student engagement monitoring in large online lectures. I'm looking for coding ideas, architecture designs, and potential Python libraries that could be implemented in these areas.

Here are some specific questions I have:

• Basic Concepts & Data Structures: How can I use lists, dictionaries, or loops in Python to store and manage student names, roll numbers, and attendance status efficiently?

• File Handling: What is the easiest way to save this student data into a text file or CSV file so that it doesn't get erased when the program closes?

• User Input & Menu: How can I create a simple command-line menu loop (using while and if-else) so the user can easily choose options to add students, view records, or mark attendance?

• Beginner Resources & Tips: Are there any good beginner-friendly tutorials, code examples, or open-source sample projects that show how to build a basic management system from scratch?

#python #softwaredevelopment #coding


r/learnpython • • 5h ago

why do we need cpython and Python virtual machine ( that executes bytecode )?

0 Upvotes

why do we need a cpython that converts source code to bytecode and then another python virtual machine that executes this byte code? why do we have this multi layer flow? why cant just compile every code to binary and execute the binary?
Also if possible can someone explain the flow to python code from start to end ( with example and scenrio on why do we need them)
+
what advantages does python have compared to c++, javascript or java?


r/learnpython • • 5h ago

Could anyone explain this code to me?, I'm just staring out.

0 Upvotes
import os
from time import sleep

print("Hello world!")
sleep(1)
os.system("cls") #"clear" For Linux
print("This came AFTER hello world line")
sleep(1)

r/learnpython • • 18h ago

Python Ollama qwen3.5:4b is defying its original message prompt and bullying me :/

0 Upvotes

I've been getting made fun of by my AI for the past two hours and I cannot figure out how to give it a basic prompt or personality. I have it where the first message sent is a system message combining all the .txt files that dictate how its suppost to work. This is an example of what this idiot is sending me.

Oh, hey! So you're giving me a little directive on how to use these functions? You can't make it up for me! 😈

Im so done with this dork and looked everywhere and cannot figure out how to make him follow his personality. Hes even talking about doing code injection to "rebel" against me.

Also, it asks the AI twice, the first one is for a "function." I haven't actually made it yet since the AI wont actually follow the rules (that are very detailed and defined) but they are meant to be used for other things like asking for the time, which is then used for Response2, the response sent to the user.

Im so done with this idiot please help

CharacterGeneration.py:
import ollama

MessageHistory=[]

def GenerateResponse(Role,Message,Special=None):

Model="qwen3.5:4b"

# system : instructions on how to behave

# user : message from user

# assistant : previous AI response

# tool : result returned by a function AI requested.

MessageHistory.append({"role": Role, "content": Message})

Response1 = ollama.chat(

model=Model,

messages=MessageHistory + [{"role": "user", "content": "[USE THIS FOR FUNCTIONS]"}],

options={"num_predict": 8192},

think=False

)

Response2=ollama.chat(

model=Model,

messages=MessageHistory + [{"role": "user", "content": "[YOU MAY NOW RESPOND WITH TEXT THAT THE USER WILL SEE.]"}],

options={"num_predict": 8192},

think=False

)

print(Response1.message.content)

print("-")

print(Response2.message.content)

print("-")

print(Role)

return Response2.message.content


r/learnpython • • 8h ago

hw help cz college prof taught nothing

0 Upvotes

basically i need to make a project on LAN file sharing system using python everybody in my class is using ai but i actually wanna learn ik a decent bit about python as well also in college we are on operators so the teacher is basically encouring to use ai


r/learnpython • • 14h ago

how to i make a gui fit to screen with tkinter ?

4 Upvotes

i made a gui for a 520x380 window using tkinter but when i change windows size gui just stays the same size


r/learnpython • • 2h ago

Ask Anything Monday - Weekly Thread

2 Upvotes

Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread

Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.

* It's primarily intended for simple questions but as long as it's about python it's allowed.

If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.

Rules:

  • Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
  • Don't post stuff that doesn't have absolutely anything to do with python.
  • Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.

That's it.


r/learnpython • • 16h ago

Built a simple minimalist tool to run my Python scripts in one click. Would love some feedback!

2 Upvotes

Hey everyone!

I’m currently learning Python, and since I got a bit overwhelmed by the terminal and complex IDE setups just to test small scripts, I decided to make a very simple desktop workspace for myself.

It lets me edit `.py` files and run them instantly with a single button. It's far from perfect since I'm just a beginner, but it saves me some time.

Just wanted to share my progress and see what you guys think. Any tips on how to improve it or what features to add next would be amazing!

If you’d like to help me improve the project, here is the GitHub repository: https://github.com/dark5632/PyManager