Swe 102 Lab

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Programming Fundamentals (SWE-102) SSUET/QR/114

LAB # 01

INTRODUCTION

OBJECTIVE
To become familiar with the Python Programming by using an Integrated Development
Environment

THEORY
Programming
The act of writing computer programs is called computer programming. A computer
program is a sequence of instructions written using a computer programming language
to perform specified tasks by the computer. There are a large number of programming
languages that can be used to write computer programs, for example: Python, C, C++,
Java, PHP, Perl, Ruby etc.

Python Programming Language


Python is a general-purpose, interpreted, object-oriented programming language.
Python was created by Guido van Rossum in the Netherlands in 1990. Python has
become a popular programming language widely used in industry and academia due to
its simple, concise, and intuitive syntax and extensive library. Python is a general-
purpose programming language. That means Python can be used to write code for any
programming task. Python is now used in the Google search engine and in mission-
critical projects at NASA etc. Python is interpreted, which means that Python code is
translated and executed by an interpreter.

Integrated Development Environment


An Integrated Development Environment (IDE) is a software application that provides
comprehensive facilities to computer programmers for software development.
Typically, an IDE contains a code editor, a compiler or interpreter and a debugger that
the developer accesses through a single graphical user interface (GUI). An IDE may be
a standalone application, or it may be included as part of one or more existing and
compatible applications. IDEs are also available online that can be accessed through a
web browser.

Using an IDE will save a lot of time and effort in writing a program. However, one
should be careful of some of the pitfalls of using an IDE as it may not be ideal for
everyone and might not be suitable in every situation. Some IDEs are very complicated
to use and may consume a lot of resources.

Lab 01: Introduction 1


Programming Fundamentals (SWE-102) SSUET/QR/114

Many IDEs support Python Programming Language. Some of the popular IDEs are
listed below.

Standalone IDEs:
• Microsoft Visual Studio Code
https://code.visualstudio.com/
• Eclipse
https://www.eclipse.org/downloads
• NetBeans
https://netbeans.org/downloads/
• Thonny
https://thonny.org/
• Anaconda
https://www.anaconda.com/distribution/

Online IDEs:
• Ideone
https://ideone.com/
• Online GDB
https://www.onlinegdb.com/online_python_debugger

Creating a Python program file with Thonny


Thonny is a free Python Integrated Development Environment (IDE) that is designed
for beginners. Thonny comes with Python 3.7 built in, so just one simple installer is
needed to get started.

Step#1: Go to https://thonny.org

Step#2: Download the version for Windows and wait a few seconds while it
downloads.

Lab 01: Introduction 2


Programming Fundamentals (SWE-102) SSUET/QR/114

Step#3: Run the .exe file.

Lab 01: Introduction 3


Programming Fundamentals (SWE-102) SSUET/QR/114

Step#4: Follow the installation wizard to complete the installation process and just
click "Next".

Step#5: After completing the installation, open Thonny IDE. A window as shown in
the following figure should open.

Lab 01: Introduction 4


Programming Fundamentals (SWE-102) SSUET/QR/114

A simple Python program


Following is a simple Python program.
#Description: Display two messages
'''Writes the words "Hello, World! and Python is fun" on the
screen'''
print("Hello, World! \n Python is fun")

print("Hello, World! \n Python is fun") instructs the computer to print on the screen the
string of characters enclosed by the quotation marks.

\n is an escape sequence that means newline. It causes the cursor to position to the
beginning of the next line on the screen.

pound sign (#) is a comment on a line, called a line comment, or enclosed between
three consecutive single quotation marks (''') on one or several lines, called a paragraph
comment.

Python programs are case sensitive. It would be wrong, for example, to replace print in
the program with Print. Several special characters can be seen (#, ", ()) in the program.
They are used in almost every program. Table 1.1 summarizes their uses.

Table1.1: Special characters


Character Name Description
() Opening and closing parentheses Used with function
# Pound sign or comment Precedes a comment line
“ “ Opening and closing quotation marks Encloses a string (i.e.,sequence
of characters)
‘‘’ ‘’’ Paragraph comments Encloses a paragraph comment

Lab 01: Introduction 5


Programming Fundamentals (SWE-102) SSUET/QR/114

Build and Run a Python Program

Step#1: Go to File > New. Then save the file with .py extension.

Step#2: Write your code in .py file.

Step#3: Then Go to Run > Run current script or simply click F5 to run it

Lab 01: Introduction 6


Programming Fundamentals (SWE-102) SSUET/QR/114

The output would be displayed in a separate window.

EXERCISE
A. Create a file named lab1.py. Write the following code in the file. Execute it and
show the output. (You can use the Snipping Tool to take a snapshot of your output
window).
1. Code:
# My first program
print("Welcome in the world of programming! \n")

Output:

2. Code:
#My second program
print("Welcome in the ")
print("world of programming! \n")

Output:

B. Write a program in Python language that prints your bio-data on the screen.
Show your program and its output.

Lab 01: Introduction 7

You might also like