This article is a step-by-step guide on how to get started into programming, including all the initial baby steps.
Unlike the traditional programming guides, this guide will focus on programming with AI-powered code generation, which could be ChatGPT or Microsoft Copilot, which are the most popular, or other AI code generation, a list of options will be listed on its own section, and it will include the just released Meta.AI.
Don’t forget that Generative AI for software development can drastically reduce the time you spend creating a program, but you still need to understand what is happening and be able to do manually fixes, programming and tests. Machines are getting smarter, but aren’t there yet, and AI-powered code generation still produces plenty of coding errors.
All the tools used in this guide are free, including the guide itself, however, if you want a bigger advantage of AI-assisted coding, consider buying a monthly premium subscription of an AI coding assistant.
If your goal is to get hired as a programer, and your employer already transitioned into using the coding generative AI tools, it’s most likely to be using coding assistance via API.
The screenshots on this guide is from a computer running Linux, but all are still valid for Windows or MacOS.
Get started
To create your first program, notice that I use the verb “create” and not “write” since the program will be created by AI coding assistant, you will need to go a list of steps:
- Understand the fundamental programming terms.
- Downloading and installing software.
- Learn how to write a prompt to output code on ChatGPT.
- How to execute a program to produce a valid output.
Once you get the first program working, this guide will assist you to move forward:
- Debugging your program - which means to find errors in your program.
- Improving your coding environment - this will allow you to write faster and understand your program better.
Terminology
If you are an absolute beginner, it’s fundamental to understand clearly these terms:
- Code - is a list of text lines which are understood by a computer in order to execute actions and produce an output.
- Program - is when you have one or more files containing code which once executed, it will produce a complete output.
In this guide the words code and program will be used interchangeably, however, code can also be a code library, a code package or just a piece of a program. - Bug - is an error on the code. That is, when a program is executed, it won’t produce the desired output due to code errors, known as bugs.
- Debugging - is the process of finding and fixing the code errors.
- IDE - means Integrated Development Environment, is a code editor that also supports program execution, debugging, syntax highlighting, code formatting among many other features.
Requirements
Python
Python is a computer language and it has become one of top most used languages, due:
- It's simple to write python code, due its English-like syntax and no boilerplate.
- Widely used in Data Science and Machine Learning.
- Large codebase available online, which made it the top elected language for AI-assisted coding.
Python Installation
You can download Python from here.
Note: Many Linux distros have Python already installed, in such case, it’s better not to update to a more recent version since it can have breaking changes.
After download and install, go to the command line, and type:
python --version
To access the command line:
- (Windows) type on windows menu:
command prompt
.
Note: On Windows, it might require a reboot. - (Linux/MacOS) type on linux menu:
terminal
Windows (the version number might be different):
Linux (the version number might be different):
Code Editor
Choosing a good code editor can help you to learn faster, providing a wide range of tools to simplify your workflow. Today, there are plenty of code editors to choose from. The author's top pick is Microsoft Visual Studio Code.
The top reasons for this pick are:
- It's free, as in free beer.
- Developed by a large community.
- It's mostly open-source - most of the source code can be inspected by any programmer.
- It runs on Windows, Linux and MacOS.
- It has support for a huge number of computer languages:
- syntax highlighting - adds colors to the code in accordance with its usage within the program.
- code formatting - automatically changes the code to look prettier¸ therefore, easier to read.
- code snippets - it allows you to insert pieces of code with a few keystrokes.
- linting - checks if the code is well formatted.
- debugging - fixing and solving code errors.
- It has full integration:
- docker containers - execute code in isolation.
- git - code versioning.
- WSL - allows the execution of the command line on Windows with the power of Linux.
- AI-assisted coding.
- Integrated terminals.
Visual Studio Code Installation
To download and install Visual Studio Code, use the following link.
When you execute it for the first time, you should see the following:
Visual Studio Code Terminals
One one of the many great features of Visual Studio Code is the support for Integrated terminals.
Instead of using an external command prompt/terminal, you can have a terminal inside Visual Studio Code, the functionality is the same, but it’s easier to see the code and its execution at the same time.
To archive this, go to the Menu → Terminal
→ New Terminal
.
Windows (the version number might be different):
Linux (the version number might be different):
Now you are ready to create your first python program!
First Program (Hello World)
Whenever you start programming for the first time, or a new computer language, the first program should be to output Hello World.
This program although incredibly simple, it allows you to verify that the fundamental tools are working.
The best way to use AI-assisted coding to generate a python program, it is to install and setup an extension on Visual Studio Code to communicate directly with ChatGPT or Microsoft Copilot but that requires setting up API keys and the setup the code editor, to bypass all this extra steps, do the following to get your started with your first python program.
- Open your web browser and type on the search bar ChatGPT web address: https://chatgpt.com/
- Write on the prompt:
write python code for hello world program
You should see the following output:
print("Hello, World!")
Note: ChatGPT isn’t deterministic, therefore, it can have a different code, in this case, most likely, it can generate different comments.
- Click on the Copy Code:
- On Visual Studio Code, create a New File. (Menu →
File
→New Text File
), and Paste the code
- Save the file (Menu →
File
→Save
) with name test.py. - On Visual Studio Code, terminal window, type:
python test.py
You should see an output of:
hello world
Explaining the Hello World program
The hello world python program has a single line:
- A line with
print("Hello, World!")
.print
is a python function that will output whatever is inside the brackets.
Second Program (Number Guessing game)
Now that you get the gist of it, with all the fundamental tools and the simple hello world program, let us try something more complex.
Again, don’t forget that: ChatGPT isn’t deterministic, therefore, it can have a different code.
write in python a number guessing game. Ask the user for a number from 1 to 5. Keep asking the user until the number matches. End the game when the user input an empty prompt
ChatGPT will output (It might provide a different solution, since it’s not deterministic):
import random
def number_guessing_game():
correct_number = random.randint(1, 5)
print("Guess a number between 1 and 5. Press Enter to quit.")
while True:
user_input = input("Enter your guess: ")
if user_input == "":
print("Game ended. Goodbye!")
break
try:
guess = int(user_input)
if guess < 1 or guess > 5:
print("Please enter a number between 1 and 5.")
elif guess == correct_number:
print("Congratulations! You guessed the correct number.")
break
else:
print("Wrong guess. Try again.")
except ValueError:
print("Invalid input. Please enter a number.")
number_guessing_game()
Explaining Number Guessing game
The Number Guessing game can be decomposed into the following actions:
- Stores a random number between 1 and 5.
- Ask the user for a number between 1 and 5.
- Checks if the number provided by the user matches the random number.
- If “yes”, it prints “Congratulations” and it ends the program.
- If “no”, it prints “Wrong guess” and goes back to step 2.
The best way to explain this more complex program is by adding comments to each line.
import random # imports external code to generate random numbers
def number_guessing_game(): # organizes the code into a function to be able to call later
correct_number = random.randint(1, 5) # assigns a random to variable “correct_number”
print("Guess a number between 1 and 5. Press Enter to quit.") # prints information
while True: # it will loop forever, unless it reaches a “break”
user_input = input("Enter your guess: ") # asks the user for a input
if user_input == "": # checks if it’s empty
print("Game ended. Goodbye!") # prints information
break # exits the function, breaking the loop
try:
guess = int(user_input) # converts the input into a number
if guess < 1 or guess > 5: # checks if the user provided a number between 1 and 5
print("Please enter a number between 1 and 5.")
elif guess == correct_number: # checks if the number provided by the user matches the random number
print("Congratulations! You guessed the correct number.")
break # exits the function, breaking the loop
else: # otherwise, prints an error message
print("Wrong guess. Try again.")
except ValueError:
print("Invalid input. Please enter a number.")
number_guessing_game() # calls the “number_guessing_game” define above
Generative AI for software development
This tutorial uses ChatGPT for AI coding assistant since it’s the most popular, but there are many other websites that support Generative AI for software development.
The following list supports free limited usage: