Friday, May 10, 2024

How do you create a 'Hello World' program using PyCharm?

 "Hello World" is a popular program sued in the introduction of many software programs made popular by Microsoft. Bern Kernighan of the Bell Laboratories used (1972) it in the documentation of BCPL when the language C was developed. It has been repeated for many languages.

Before we do this in the PyCharm, it is important to look at the PyCharm interface in some detail. The PyCharm IDE interface is just like other interfaces like Visual Studio IDE. That said, here are some major parts of this interface.

When you start the IDE interface, the first screen you encounter is the Welcome Screen shown here. In this screen, you have access to take a quick tour if you desire to do so.



The navigation pane on the left gives you access to the Projects, Customization, Plugins, and learning tools.

If you have already created a project, you could Open it, create a new one, or get one from the version control system as shown in the above image.

Since this the first time using this interface. Click to create a New Project. This is a Python IDE and therefore it uses Pure Python whose version is 3.12. Django is another option we will not be using now.

The default Project Name is python Project. Overwrite this and provide the name Helloworld as shown. Leave the location as is. Do not click to Create Git Repository. Place check park for Create a main.py welcome script as shown. Note that the project will be created in the C:\ drive at the location, C:\Users\hoden\PyCharm Projects\HelloWorld. The IDE also creates a virtual environment at the location shown on this screen. We will visit virtual environments later.

Now, click Create at the bottom. The program starts running and takes a minute or so and you will see the screen shown here displayed. The Helloworld main program is created. main.py is python file created and the main.py script is shown on the right.

The project is ready to run. If you run the code on the right by clicking the green button shown in the above image. You will immediately see the result of running at the bottom as shown below. The program prints the words, "Hi, PyCharm".

What if you want it to print, Hello World".? Go back to the project screen as shown. Now, overwrite PyCharm in the bottom of the main.py's code window shown.

Now, hit the green button again. You will see, "Hi, Hello World" as shown.

==============

C:\Users\hoden\PycharmProjects\Helloworld\.venv\Scripts\python.exe C:\Users\hoden\PycharmProjects\Helloworld\main.py 

Hi, Hello World

Process finished with exit code 0

=====================

Where did the Hi come from?

Think how you can change this.

No comments: