Write and Run Sample Python Script

By | July 16, 2019

How to Write and Run Sample Python Script: In this tutorial we will write a sample Python script To Input name of the user and display a Welcome message to the user.

We will suppose that you have already installed Python 3.7 on your computer system. If you have not installed the Python 3.7, please follow the steps provided in our Python tutorial – How to download and Install Python on Windows from Python.org – the official Python website.

What do You Need To Write and Run Sample python Script

You will need the Python programming language installed on your computer. The latest version is the Python 3.7.4. It is bundled with a built in Integrated Development Environment which is known as IDLE.

How to write and run sample Python script

How to write and run sample Python script

The IDLE stands for Integrated Development and Learning Environment for Python script writing and executing these python scripts or programs.

The IDLE provides us with a simple but nice code editor. We can easily write a sample Python script or Python program in this code editor. After writing our Python script in the code editor, we will use the IDLE to run this script and get the required output.

Start IDLE from Start Button and Search Option

Start IDLE to write and run sample python scripts

Start IDLE to write and run sample python scripts

How to Write and Save Python Program in IDLE

Click on File menu of the IDLE user interface, and select New File.

Open new Python file in IDLE

Open new Python file in IDLE

A blank file will open in a new window.  Write your sample Python program ‘Welcome User by Name ‘ in this code window and save the file. The Python program has a name and a ‘.py’ extension. For example we will save this Python file with the name as “welcome.py”.

Type the following code.

Note: print() is builtin function. It will display a message string and value of a variable. For example, print(‘Welcome ‘ + user_name) , here a string ‘Welcome’ is concatenated with the value of a variable user_name. ‘+’ is a concatenation operator here.

Moreover, input() function is used to get input values from the user on run time. It returns a string. For example in this example it returns the name of the user. The entered name is stored in a variable user_name.

# This Python Script will
# input a name from the user
# and display a welcome message
# by name.

user_name = input('Enter you name, please:')
print('Welcome ' + user_name)

Click on File menu and select Save option. Type a file name like ‘welcome.py’, click on save button.

Save the Python file

Save the Python file

How to Run Python Program in IDLE

After saving the Python program, click on Run menu and select Run Module or press keyboard short cut F5.

Press F5 to run python program in IDLE

Press F5 to run python program in IDLE

The program will execute and show the output:

Enter your name, please:

The user will enter his name say ‘Ahmad’

Enter your name, please: Ahmad     [and Press Enter]

The program will show welcome output message by name as:

Welcome Ahmad.

sample run output of python program in IDLE

sample run output of python program in IDLE

Congratulations You have done! finally, you have written and executed your first sample program in Python programming language, using the IDLE integrated development environment by Python.org.

One thought on “Write and Run Sample Python Script

  1. Pingback: Python file program read numbers write squares | EasyCodeBook.com

Leave a Reply

Your email address will not be published. Required fields are marked *