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.
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
How to Write and Save Python Program in IDLE
Click on File menu of the IDLE user interface, and select New File.
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)
How to Save Python Program on Disk?
Click on File menu and select Save option. Type a file name like ‘welcome.py’, click on save button.
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.
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 follows:
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.
Pingback: Python file program read numbers write squares | EasyCodeBook.com