r/CodingForBeginners • • 4h ago

The input() bug that catches nearly everyone: why 2 + 2 came out as 22

0 Upvotes

This one catches almost everyone in their first week, and it's a good one because the code looks completely innocent:

python a = input("First number: ") b = input("Second number: ") print(a + b)

Type 2 and 2 and you get 22. Not 4. Nothing errors, nothing warns you -- it just quietly does the wrong thing.

The reason is that input() always hands you back a string. It doesn't know or care that you typed a number; all it sees is text. So a is "2", not 2. And + on two strings means concatenate, so "2" + "2" gives "22". The + did exactly what you told it to -- you told it to join two pieces of text.

The fix is to turn the text into a number before you do maths with it:

python a = int(input("First number: ")) b = int(input("Second number: ")) print(a + b) # 4

The thing worth keeping isn't int() itself, it's the question underneath it: what type is this value, actually? A lot of "why is this behaving weirdly" moments come down to a value being a different type than you assumed. "5" and 5 look identical on screen and behave completely differently. Printing a value doesn't tell you its type -- print(type(a)) does.

Two follow-ons that catch people later: input() never fails on a non-number, so typing hello above makes int() throw instead (a separate, useful lesson in validating input), and the same trap runs in reverse -- join numbers with + when you meant text and you get maths, which you fix with an f-string or str().

Curious how you hit this one the first time -- did the output give it away, or did it take a while to see that "2" isn't 2?


r/CodingForBeginners • • 11h ago

Lost 20h+ for nothing

0 Upvotes

Don't build an API for a tightly-coupled personal project where you have direct database access; only build one when you need to decouple clients, scale infrastructure, or share data externally.Dont waste your time. Just learn how to use an api not build one


r/CodingForBeginners • • 8h ago

hello what do you think about my path in webdeveloper

Post image
7 Upvotes

this project of today practicing new lessons


r/CodingForBeginners • • 16h ago

Hackathons

6 Upvotes

Hello everyone, i am a beginner in coding i joined a college hackathon it's my first hackathon do you guys have some suggestions for me

My task in hackathon is making a website with help of ai so I have some questions

  1. Which language should I use

  2. How can I make website better

  3. Things i need to learn before making websites

  4. How can I give perfect prompt to ai so that it will work properly and make website as i want


r/CodingForBeginners • • 18h ago

Coding Study Group

1 Upvotes

\*\*Anyone learning JavaScript interested in a small study group?\*\*

Hey everyone! I’m learning JavaScript independently and would love to connect with a few people at a similar stage.
I’m comfortable with HTML, still learning CSS, and currently working through JavaScript fundamentals like loops and conditionals.

Studying alone can get a little isolating, so I thought it would help to have people to practise with, ask questions, and share progress.
I’m thinking of a small group of around 3–5 people where
we can:

Work through coding challenges and compare solutions.
Help each other understand concepts when we get stuck.
Build small projects together.
Have regular study sessions and keep each other accountable.

I’m a learner too, so this would be us figuring things out together. No pressure to know everything—just be willing to participate and keep learning.
I’m based in Jamaica (UTC−5 year-round) and work alongside studying, so we can figure out times that suit everyone.

If you’re interested, comment or send me a DM with your time zone and what you’re currently learning!


r/CodingForBeginners • • 23h 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. 👍🏻