Write your first program for absolute beginners!

Write your first program for absolute beginners!

Your first steps to start the programming journey!

ยท

6 min read

Introduction

In this article, I will try to help you write your first program in python. Normally, I write articles about some programming concepts that are intended to be read by people who have already knowledge about the programming principles. But in this blog post, I will try to help absolute beginners to write their first program. So, if you are an absolute beginner who has no knowledge or very shallow knowledge about programming, this article is for you!

What you will learn from this article?

As stated before, this article is for absolute beginners, by the end of this article, you will learn the following :

  • Why should you learn to program?

  • What is a programming language?

  • What is Python?

  • Why Python?

  • Basics of python

Why should you learn to program

As a beginner you may be wondering why you should learn to program, well there are many reasons why you should start this career, programming skills are increasingly in demand by businesses due to the need for automation and problem-solving. Companies are hiring programmers to create and manage their websites, create software, develop algorithms to solve problems and automate tasks. As a programmer, you will be able to write code to solve a specific problem or develop an entire software program. In addition to working in a company, as a programmer you can create your own projects to earn a living, among these projects, you can provide courses, start freelancing and maybe write a book!

What is a programming language?

A programming language is a computer language that programmers use to communicate with computers and develop software for computers. Programming languages are a set of texts that are converted to machine code. In general, a programming language is used to create programs that perform a specific task.

What is Python?

Python is a high-level, general-purpose programming language, that can be used for different tasks. Python is also one of the most used programming languages in the world, in my opinion, every developer should spend some time learning python because it's extremely easy for beginners, it can be used to develop basic algorithms quickly and without having to worry about the datatypes and other details. It's a popular language for data science, machine learning and deep learning. Python is also used for scientific and computational applications.

Why Python?

I choose python for this article because python is a relatively easy language, as an absolute beginner, python is really suitable since you will not be worrying about concepts like datatypes, pointers etc...
In addition, since we will create simple general-purpose programs, python is the best choice for this task. Of course, other languages are widely used, to help you understand the difference between these programming languages, I write an article about the most programming languages to learn in 2023 and the difference between them. 5 Most Popular Programming Languages to Learn in 2023

Python can be used in the following fields :

  • Data Science / Machine learning

  • Mobile Apps

  • Websites

  • Computer Science

  • Games

  • Data Processing and Analysis

  • Hardware / Sensors / Robots

  • Automating Work Tasks

Note that if you are interested in learning other languages like C# Learn C# for absolute beginners

Where can you write python code?

To write python code, you need a text editor, several texts editors are available and open source like pycharm, sublime text, visual studio code and more... but in this article, we will keep it simple, we will use an online text editor like Online Python - IDE, Editor, Compiler, Interpreter

Basics of python

Now, when you first open your text editor, you might find a screen like the following :

We will write code in the main.py file and then execute our code, the output will be then written in the terminal. First, let's print something like "I like python".

print("I like python")

Inside the quotation marks, you can write whatever you want and the print function will log that in the terminal.

Now, let's ask the user to input two numbers and then calculate their sum and print it. For that, we will use the function input and convert the input to int the function input takes a text as a parameter. Then we assign the value entered by the user to two variables called a and b then we calculate the sum and print it.

a = int(input("Enter the first number :"))
b = int(input("Enter the second number :"))
c = a + b
print("The sum is : ", c)

The output of the previous code will be as follows :

Now, that we create our first code, let's go a little bit deeper and learn about functions, a function in a programming language takes parameters as arguments, do some calculations and then return a value. To create a function in python, we use the leyword def let's define a function that takes two parameters a and b, calculates the sum then return it.

# This is a comment, it's ignored when running the code!
def addNumbers(a, b):
    c = a + b 
    return c

The return value of this function can be stored in a variable called sum form example :

sum = addNumbers(5, 4)

Note that you can give the function the name you want (there are some reserved keywords that you shouldn't use like int, str ...). Now, to print the previous value we can use the function print

print(sum)

Now, you can write other functions yourself to practice what we have learned.

What should you learn more to master Python?

Even though Python is easy to learn, there are however several concepts you should master to become a python developer. First, you should spend a lot of time learning the basics of python, and then you can move on to learn about python libraries and frameworks. Among the programming concepts you should learn :

  • Learn Python syntax

  • Python variables and datatypes

  • Lists, tuples, sets and dictionaries

  • Python if and else statements

  • For and while loops

  • Python functions and lambda functions

  • Python arrays classes and objects

Of course, this is not an exhaustive list, however, you should spend some time learning about these concepts. Then, the next step will be to start working on projects. Some of the projects on which you can work to develop your skills :

  1. Guess the Number Game (computer)

  2. Rock, paper, scissors

  3. Hangman

  4. Countdown Timer

  5. Password Generator

  6. QR code encoder/decoder

  7. Tic-Tac-Toe

  8. Minesweeper

  9. Sudoku Solver

  10. Snake

If you want a complete guide to object-oriented programming in python, have a look at my previous article: Object oriented programming from scratch in python

Conclusion

This is a very simple tutorial for absolute beginners and is intended to give you some insights about programming languages before you dive into this field, in the next tutorials I will try to provide more details about programming languages.
Like, leave a Comment and follow for more! Thank you very much!

Did you find this article valuable?

Support Interrupt101 by becoming a sponsor. Any amount is appreciated!

ย