Writing Your First Code-A Simple Project to Kickstart Your Learning

Over 2 decades of software engineering experience, including over a decade in building, scaling and leading engineering teams.
Search for a command to run...

Over 2 decades of software engineering experience, including over a decade in building, scaling and leading engineering teams.
No comments yet. Be the first to comment.
Over 2 decades as a software engineering professional, I've worked in multinationals enterprises and tech companies."Software Engineering 101" series distills my experiences to guide software engineers through every stage, from year 0 to year 20.
Debugging is an essential skill for any programmer, whether you're a beginner or an experienced developer. It’s the process of identifying, analyzing, and fixing bugs—errors or issues in your code that cause it to behave unexpectedly. In this post, w...
“If your product is good enough, it should sell itself.”That’s the common myth most founders fall for when adopting Product-Led Growth (PLG). But the truth is, even the most iconic PLG companies — Slack, Zoom, Notion, and Atlassian — all built their ...

Every leader eventually faces this question:Should I be out front, showing the way — or behind the scenes, letting my team shine? The truth is, both matter.Some moments call for visible action; others call for quiet guidance.The art of modern leaders...

When you build SaaS products, one of your greatest strengths is empathy. To truly serve your users, you need to step into their shoes. A customer journey map is the tool that helps you see that walk, from the moment someone hears about your product t...

While taking up the Software Engineering career two paths often emerge: that of the generalist engineer and the specialist engineer. Both roles are crucial, but they serve different purposes depending on the company's goals, team structure, and proje...

Imagine life in ancient times. You’re a farmer who wants to trade some grain for meat, but there’s a problem: the shepherd you’re dealing with doesn’t need grain. Without a way to assign a common value to your goods, you’re left with a sack of wheat ...

Embarking on your coding journey is both thrilling and challenging. Whether you're aiming to become a software engineer, a web developer, or simply want to learn how to code, the best way to start is by diving right in and writing your first code. In this post, we’ll guide you through a simple project that will help you kickstart your learning, giving you a hands-on experience that lays a solid foundation for your future coding endeavors.
Starting with a simple project offers several advantages:
Hands-On Learning: Writing code from scratch helps you understand programming concepts better than just reading about them.
Immediate Feedback: You can see the results of your code instantly, allowing you to learn through trial and error.
Build Confidence: Completing a project, no matter how small, boosts your confidence and motivates you to tackle more complex challenges.
Foundation for Growth: A simple project provides a base from which you can expand your skills, adding complexity and new features as you learn more.
One of the best beginner projects is creating a basic calculator. It’s simple enough for a first project but covers essential programming concepts like variables, functions, user input, and conditional statements. Plus, a calculator is something you can immediately use and test.
Before writing any code, you need to set up your development environment. Here’s what you’ll need:
A Code Editor: We recommend using Visual Studio Code (VS Code) because it’s free, beginner-friendly, and packed with useful features.
A Programming Language: For this project, we’ll use Python, a popular language known for its readability and ease of use.
Installing Python:
Download and install Python from the official website (python.org).
Ensure Python is added to your system’s PATH during installation, so you can run Python scripts from your command line.
With your environment ready, it’s time to write some code! Open your code editor and create a new file called calculator.py. This will be the script where you write your calculator program.
Starting Your Script:
# Simple Calculator in Python
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y != 0:
return x / y
else:
return "Error: Division by zero is not allowed."
In this code, we’ve defined four basic arithmetic functions: add, subtract, multiply, and divide. Each function takes two arguments (x and y) and returns the result of the respective operation.
Next, let’s allow users to input numbers and choose an operation. This is where you’ll use Python’s built-in input() function.
Adding User Input:
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
choice = input("Enter choice(1/2/3/4): ")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
Here, the user can choose the operation they want to perform and input the numbers they want to calculate.
Finally, we’ll use conditional statements to perform the chosen operation and display the result.
Finalizing the Calculator:
if choice == '1':
print(f"The result is: {add(num1, num2)}")
elif choice == '2':
print(f"The result is: {subtract(num1, num2)}")
elif choice == '3':
print(f"The result is: {multiply(num1, num2)}")
elif choice == '4':
print(f"The result is: {divide(num1, num2)}")
else:
print("Invalid input")
This code checks the user’s choice and calls the corresponding function to perform the calculation. The result is then printed out.
Save your file and run the script to see your calculator in action. You can run the script from the terminal by navigating to the folder where your calculator.py file is located and typing:
python calculator.py
Follow the on-screen prompts to select an operation and input numbers. Your calculator should output the correct result.
Once you’ve successfully created your basic calculator, you can expand the project to add more features:
Add more operations: Include operations like exponentiation, square root, or modulus.
Improve the user interface: Create a graphical user interface (GUI) using libraries like Tkinter.
Error handling: Enhance the script to handle invalid inputs or unexpected errors more gracefully.
Writing your first code with a simple project like a calculator is a great way to start your coding journey. It allows you to apply basic programming concepts in a practical way, giving you the confidence and skills needed to take on more complex projects. Remember, every coding journey begins with a single line of code—so don’t hesitate to dive in and start building!
By following this guide, you’ve not only learned how to write your first code but also laid the groundwork for future success in programming. Keep experimenting, keep learning, and most importantly, keep coding!