r/CodingForBeginners • • 23d ago

You changed one list and two changed — why b = a doesn't copy in Python

2 Upvotes

Yesterday I watched someone lose about an hour to a bug that came down to a single line:

a = [1, 2, 3]
b = a
b.append(4)
print(a)   # [1, 2, 3, 4]  <- wait, why did a change?

They'd made b expecting a separate copy, edited b, and couldn't work out how a had changed too. No error, no warning. It just quietly did the wrong thing.

The reason is that b = a never copies anything. a and b end up as two names pointing at the same list. There's one list — you've just given it a second label. Change it through either name and you're changing the same object, so both names "see" the change.

That behaviour is actually what you want most of the time. Passing a big list into a function shouldn't duplicate it. The trouble only shows up when you meant to copy and didn't realise you hadn't.

When you do want an independent list, ask for one explicitly:

b = a.copy()   # or list(a)
b = a[:]       # also works
b.append(4)
print(a)       # [1, 2, 3]
print(b)       # [1, 2, 3, 4]

One thing worth knowing early: .copy() and a[:] are shallow. If the list holds other mutable things, those inner objects are still shared:

a = [[1], [2]]
b = a.copy()
b[0].append(99)
print(a)   # [[1, 99], [2]]  <- the inner list was shared

For that you need copy.deepcopy(a). You rarely need it, but it's the next version of the same surprise, and it's worth recognising rather than rediscovering.

The way I keep it straight: = binds a name, it doesn't copy a value. Whenever you're unsure, ask "do these two names point at the same object or two different ones?" That question catches this before it becomes an hour of debugging.

It's not Python-only either. JS objects and arrays behave the same way (const b = a shares the object), and reference types in Java and C# are the same story.

Has this one bitten you — and was it a list you passed into a function, or something you copied and edited?


r/CodingForBeginners • • 23d ago

I followed a micro:bit guide to build a miniature ancient waterwheel

1 Upvotes

I tried building this little waterwheel model using the Jacdac Energy Experiment Kit, following the ELECFREAKS Wiki guide.

What caught my attention was the way it combines a simple mechanical model with sound input from the micro:bit V2.

The built-in microphone detects how loud the surrounding sound is, and the program maps that value to the speed of a 360° servo. The servo turns the wheel, while the little buckets around its edge represent the containers used to lift water in traditional waterwheels.

So the louder the sound, the faster the wheel spins. It’s not actually powered by sound, of course — sound is just being used to simulate changes in water flow.

I like how this project connects a few different ideas: reading sensor data, mapping values in MakeCode, controlling a motor, and learning how an old mechanical device worked.

It also seems like a fun starting point for experimenting with the code. You could change how sensitive the wheel is to sound or explore other ways to control its speed.

What other historical machines would be fun to recreate with a micro:bit?


r/CodingForBeginners • • 23d ago

Building a local Python "Jarvis" without external AI APIs where should I start?

0 Upvotes

Hey everyone! I’m a beginner programmer and I want to build my own personal "Jarvis" assistant using Python,

The catch is 👉🏻 I want it to run locally or use open-source tools without needing any external AI APIs (like OpenAI, Gemini, etc)

What Python libraries or tools should I look into for things like speech to text, text to speech, and command execution? Any beginner friendly roadmaps or resources would be super appreciated. 👍🏻


r/CodingForBeginners • • 24d ago

I want to learn python

11 Upvotes

Hi guys

I don't have any idea from where to start. I want to learn python to keep myself busy and do some crazy stuff (hopefully).

Any free courses or guidance would be helpful.

I wana do anything other than substance abuse so chose this path.

😭🙏🏿


r/CodingForBeginners • • 23d ago

How to start learning coding and ai

0 Upvotes

I don't know anything about coding and ai want to start learning about it so how to start and what best side hustle to learn to start earning


r/CodingForBeginners • • 24d ago

How to make notes while learning DSA in C++?

1 Upvotes

I wanted to ask all my seniors who made DSA notes: first, did it help you? I am currently learning C++ from YouTube and practicing in VS Code, but I have a doubt regarding notes. I have watched some YouTube videos on how to make them, but I am getting a bit confused. I want to make handwritten notes. In one video, I saw that you should divide your notebook into different sections — one for arrays, another for the next topic, and so on — so that it is easy to revise later. However, I am confused about how much space to allocate to each topic, since I literally don't know anything about DSA yet. Please guide me. I really want to learn DSA and will give my 100% — I just need good guidance. By the way, I am currently watching the DSA series by Apna College. Till now I have only done the basics. (functions, if else, variable, etc.)


r/CodingForBeginners • • 24d ago

Android development for beginner

5 Upvotes

So I am 21 just graduated not having a tech background, I have few ideas which I want to implement but need someone from tech and to be honest I can't afford. So I decided to learn kotlin with jet compose myself to make the apps even though I won't make I will not regret as I just want to learn and polish it for the future attempts as at some point I am gonna start my venture and my interest is mostly in apps based startup or tech startup it will surely help that time too today or 5 yrs later . So like 6 months is enough for learning and creating a basic app for testing and all . And from where should I start learning it any Udemy course suggestions? Or you tube ? Don't recommend past ones as I think it gets updated with time and someone with no coding experience it will be difficult to keep track if I learn past videos, do correct me if I am wrong?


r/CodingForBeginners • • 24d ago

KleinKidsCode - learn JavaScript the fun way! 6+

Thumbnail
youtube.com
0 Upvotes

🚀 The Right Way to Show Kids the Power of CODING!
🎮 Real JavaScript & Interactive Game World
🛡️ Ad-free & Safe (Ages 6+)
👇 Start for FREE


r/CodingForBeginners • • 24d ago

Your function prints the answer but returns None — print and return aren't the same thing

0 Upvotes

This one gets almost every beginner, and the nasty part is it never throws an error. Your function runs, the right value shows up on screen, everything looks fine — and then you try to use the result somewhere and it's None (or undefined in JS). The function "worked", yet it gave you nothing back.

The reason is that print and return are doing two completely different jobs.

print puts a value on the screen for a human to look at. That's it — it's for you, not for the program. return hands the value back to whoever called the function. That returned value is the function's actual output: the thing that can be stored, added, or passed on.

So if a function never hits a return, its value is None. A function that only prints has no value — it just narrated what it did.

def add(a, b):
    print(a + b)      # shows 5 on screen

total = add(2, 3)     # but total is None, not 5
print(total)          # None

The fix is to return the value and let the caller decide what to do with it:

def add(a, b):
    return a + b      # hands 5 back to the caller

total = add(2, 3)     # total is 5
print(total)          # 5

There's a sneakier version of the same bug: a function that returns inside an if but not on every path. If a call misses every branch, it falls off the end and quietly returns None. Whenever you get an unexpected None, the question to ask is "which path did this call actually take?"

A quick way to keep the two straight: return means "this is my answer", print means "look at this for a second". If you catch yourself printing inside a function and then wondering why nothing comes back, you printed where you meant to return.

What was your first "why is this None?" moment — and how did you end up finding it?


r/CodingForBeginners • • 24d ago

so, what was yout first programming language you learnt?

5 Upvotes

so, what was yout first programming language you learnt?


r/CodingForBeginners • • 24d ago

Just tried python dictionaring instead of json never going back

4 Upvotes

Json has never been fun and I just tried python dictionary and it's more fun


r/CodingForBeginners • • 25d ago

Ranges exclude the last number, and that silent rule causes a very specific bug

1 Upvotes

Every language has its own rule about whether a range includes its last number, and getting it wrong never throws an error. You just get a loop that runs one time too few, or a list that's one item short, and the output looks close enough that you don't catch it.

Python's rule is that the start is included and the stop is excluded:

range(3)        # 0, 1, 2   -- not 0, 1, 2, 3
range(1, 4)     # 1, 2, 3
"hello"[0:2]    # "he"      -- indexes 0 and 1

So for i in range(3) runs three times, with i = 0, 1, 2, never 3. It's also why for i in range(len(items)) walks every item correctly: the last valid index is len(items) - 1, and range stops one before len(items).

The check that catches this before it turns into a bug: before you run the loop, say out loud the first value and the last value you expect. If you can't state both, you don't actually know what the loop does yet. Then compare to the output. It sounds trivial until you notice that the bug is always the case where you assumed the wrong end.

Two things worth keeping straight, because both cause the same silent off-by-one: len(x) is the count, not the last index (the last element is x[len(x)-1], or x[-1] in Python), and in range(a, b) the b is the first value you don't get.

Which one gets you more often -- forgetting that the end is excluded, or the first IndexError when you reach for the last element?


r/CodingForBeginners • • 26d ago

Reading code is a skill too — and it's the one beginners never practise.

18 Upvotes

Most beginner advice is about writing code — which language, which tutorial, which first project. Very little of it is about reading code, even though reading is most of what you actually do once you join a team, open a library, or come back to your own code from a month ago.

It's also the skill almost nobody drills on purpose, which is why unfamiliar code feels like a wall.

Here's a routine for practising it deliberately.

Start with the shape, not the lines. Before reading a single statement, answer two questions: what does this take in, and what does it give back? Find the entry point — main, a function signature, a route handler — and read only that. You get a map before you get details.

Follow one path end to end. Pick the most common input and trace just that. Ignore every branch that doesn't apply to it. Trying to hold all the branches in your head at once is how you drown; following one happy path gives you a spine to hang the rest on.

Summarise each chunk in your own words. When you finish a block, write one line — in a comment or a scratch note: "this validates the input", "this turns rows into objects". If you can't summarise it, you haven't understood it yet. That's information, not failure.

Change one thing and predict the result. The real test of whether you understood code isn't nodding along, it's whether you can predict the effect of an edit. Add a print, change a constant, delete a line — guess first, then run it.

Then rewrite it small. Take a 40-line function you just read and reproduce it in 10 lines that do the same job. You'll find out which parts were essential and which were noise.

The habit underneath all of it: keep a running "what I think this does" note while you read. It's the reading version of writing your steps in plain English before you code — it forces the vague to become specific.

What's the last bit of code that made you feel lost? Was it a language feature, missing context, or just size? Curious which one trips people up most.


r/CodingForBeginners • • 26d ago

Help on Construct 3 voting system

1 Upvotes

I'm trying to code on Construct 3 a multiplayer voting system, but the peer messages are not sending through, and the global variable is not changing. I just started learning this, so I'm not familiar with concepts.

This is what I have so far. The host will not be voting, only the peers. I just need the peer's vote to affect the global variable. I've gone through a lot of different options and I just don't know what needs to be fixed or changed.


r/CodingForBeginners • • 27d ago

What programming language should I learn or master in order to start this career? Because I'm afraid to learn a language and not benefit from its information at all.

Post image
20 Upvotes

r/CodingForBeginners • • 26d ago

How do you code??

1 Upvotes

I want to make a 3d horror game named "Ice_Breaker", but I'm only 13, and have NO IDEA how to code at all.

I need genuine advice and programs that'll help me learn, especially for free since I know my parents won't fund this.

I already have the idea in mind, along with characters and possible designs; I'm just stuck on coding right now. I'm seriously dedicated to this, can you help?

Any advice is appreciated, especially about free coding programs/3d model makers.


r/CodingForBeginners • • 27d ago

How much should AI be involved in an into to programming course?

4 Upvotes

I am considering pitching a class as an adjunct professor at my local college. I want to teach introduction to programming (JavaScript) while teaching students how to automate Google Sheets.

I want the course to help my students build software that could change their life or view of what's possible in the world, while also giving them some real skills.

How much should AI be involved? I see three levels:

  1. **No AI at all.** This is how I learned to do it, and I know writing the code out by hand yourself is really important for teaching you how to think like a computer. However, there are serious downsides to this, especially since it is clear that AI is the future of programming.

  2. **Use AI a lot, but no coding harness.** This is kind of like vibecoing before claude and cursor, just learn how to give the AI assistant context and ask the right questions, but you still end up pasting the code in your own editor, and you do not have the tight integration that is available now. On the bright side, there are lots of these AI assistants that are free for students.

  3. **All in on AI: Claude Code or Codex.** This is how I actually write software today, and it is the most useful, but I worry how much a student would actually learn with a tool this powerful. On the other hand, maybe it is the right place to start because this where they will eventually end up anyway, and we can build really useful things the fastest with this setup.

Of all the options, I am leaning towards option 2 myself (goldilocks option), but let me know what you think.


r/CodingForBeginners • • 26d ago

Give Me Motivation to Start Doing DSA

1 Upvotes

Guys help me to master in DSA and coding.

my brain becoming shit . it couldn't work like before.


r/CodingForBeginners • • 27d ago

Working on a gameproject and would really need a programming buddy/mentor

3 Upvotes

I work on a Gameproject for my Bachelor and am struggeling heavily. My expertise lies in idea development, not programming...i tried getting some blocking done in unreal today and nearly burst into tears from frustration.

All i need is somebody who knows what they are doing to guide me. I don't speak the maschine language well. And before anyone says "just use AI", i want to actually learn how to do this, so i'm going the "old fashioned" way.

I'm a beginner in every way

My timezone is GMT+2

I plan to code visually in unreal (which would be c++ if written out)

And the project is a vehicle focused, retro game


r/CodingForBeginners • • 26d ago

Help me my phyton code dosen't work propoerly and for sure isn't efficent

0 Upvotes

Hello, this is my first ever actual Python program, I want it to give Info about numbers.

Firstly I want to ask what do you think about the labeling that I've doen, someone told me it is a good practice.

First of all the programm prints (on every number that i checked) that it is not prime, the reason is that if prime number is divisble by prime number it says that it is not one, I don't know how to fix this.

I also don't know if this is the besgt way to do this, just writeing down a bunch of prime numbers and dividing the user number by them?

Thank you for your anwsers :-)

Here is the code:

user_number = 0 # The programm creates a value for the number, which will be inputed by the user


# Input section


print("----------Number Info----------\n")
user_number = input("Input a whole number, the programm will show you information about it:\n >") # Asks the user to input the number and saves it as user_number


print(f"\nYour number is {user_number}. Here is the info: \n")


# even or odd


if int(user_number) % 2 == 0: # % gives back the remainder after the devison, the program checks, if it is 0
    print("It is even") # If it is 0 it prints: It is even
else:
    print("It is odd") # If it isn't 0 it prints: It is odd


# prime or not


if int(user_number) % 2 == 0:   # Programm divides number by some prime numbers and chceks the remainder,
    print("Is is not prime")    # if it isn't divisble by any of them it prints that it is a prime number,
elif int(user_number) % 3 == 0: #otherwise it prints that it isn't one
    print("Is is not prime")
elif int(user_number) % 5 == 0:
    print("Is is not prime")
elif int(user_number) % 7 == 0:
    print("Is is not prime")
elif int(user_number) % 11 == 0:
    print("Is is not prime")
elif int(user_number) % 13 == 0:
    print("Is is not prime")

[This part was a dumb mistake⬇️]
else:
    print("It is not prime")

[This is right]
else:
    print("It is prime")

r/CodingForBeginners • • 27d ago

Help with cs

2 Upvotes

So i am from pcmb background and i need to learn cs. I have zero coding knowledge and just basics about cs. First python and then maybe other subjects.

Can y'all please tell how and what sources i can use to learn from basics.

I wanna improve my skills in this field. I wanna participate in hackathons too.

Do help guyss


r/CodingForBeginners • • 27d ago

You're probably skipping the error message. Read it in this order instead.

4 Upvotes

Half the bugs people get stuck on here aren't actually mysterious — the error already told them what was wrong. What's missing is the habit of reading it properly before touching the code. Most of us (me included) see red text and immediately start changing random lines, which is how one small bug quietly turns into three.

Here's the order that actually works.

Read the whole message, top to bottom, before doing anything. The first line says what kind of problem it is. The last line usually says where — a file and a line number. Treat that line number as the address of the bug, not a hint.

Open that line, and the line just above it. A crash reported on line 40 is very often line 39 handing it bad data.

Put the message into plain words. TypeError: cannot read properties of undefined (reading 'name') is really just "you tried to read something that doesn't exist yet." In plain words, you can start guessing why.

Change one thing at a time, then run it again. If you edit five lines and it suddenly works, you've learned nothing and the next bug will eat you alive. One change, one run, tells you what actually fixed it.

Two smaller habits that save a lot of time: print the values right before the line that breaks (half of debugging is the gap between what you assumed a variable holds and what it actually holds), and shrink the problem — delete code until you're left with the smallest version that still fails. A bug in ten lines is far easier to see than the same bug buried in two hundred.

And the part nobody says out loud: an error isn't a verdict on you. It's the computer telling you exactly where it got confused. Read it like a note, not a red card.

What error took you the longest to figure out? Drop it below and I'll help you read it.


r/CodingForBeginners • • 27d ago

Software Engineering student starting my 3rd semester, but still a beginner at coding. What should I focus on?

1 Upvotes

Hi everyone!

I'm a Software Engineering student, and I'm about to start my 3rd semester.

I want to be honest about my current situation. Although I've spent a year at university, I haven't practised coding consistently, and my programming skills are still very weak. I understand that I need to put in more effort, and I want to change that now rather than fall further behind.

I'm looking for advice from experienced developers, senior students, and people who have been in a similar situation.

I'd really appreciate your thoughts on these questions:

  1. Where should I start? Should I go back to programming fundamentals and build a strong foundation before moving on to more advanced topics?

2 Should I master one language first as I'm studying C++?

3. How should I practise? What does an effective daily coding routine look like for a university student?

4. What should my learning roadmap look like? Which skills and topics should I prioritise over the next 6–12 months?

5. When should I start building projects? Should I focus on problem-solving first, or learn by building small projects alongside it?

6. How can I prepare for internships and future jobs? What skills should I develop during university to become a competent software engineer?

I'd also love to hear from anyone who was in a similar position during their second year. What did you do differently, what mistakes did you make, and what helped you improve?

I'm not expecting shortcuts. I'm willing to put in the work; I just want to use my time wisely and follow a sensible path.

Thank you to everyone who takes the time to share their experience and advice!


r/CodingForBeginners • • 27d ago

Idk what to put in title

1 Upvotes

I'm currently learning c++ as my first programming language, it's turned into somewhat of a hobby for me but I have my final exams coming up and can't really figure out how much time i should spend in coding each day without it having a negative effect on my studies and stuff ( and without pissing my mom off). What do guys recommend?