0% found this document useful (0 votes)
3 views56 pages

Module 06 - Basic Programming Concepts

The document provides an overview of basic programming concepts, including the distinction between low-level and high-level programming languages, the roles of compilers and interpreters, and the importance of variable declaration. It also introduces Boolean logic and algebra, detailing operators and their evaluations, as well as conditional statements in programming. Additionally, it touches on systems analysis and design, software development approaches like the Waterfall and Agile methods, and the types of functional and non-functional requirements in system development.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views56 pages

Module 06 - Basic Programming Concepts

The document provides an overview of basic programming concepts, including the distinction between low-level and high-level programming languages, the roles of compilers and interpreters, and the importance of variable declaration. It also introduces Boolean logic and algebra, detailing operators and their evaluations, as well as conditional statements in programming. Additionally, it touches on systems analysis and design, software development approaches like the Waterfall and Agile methods, and the types of functional and non-functional requirements in system development.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module No: 06

Basic Programming Concepts

168
6.1. Introduction

Computer programs are collections of instructions that tell a computer how to interact
with the user, interact with the computer hardware and process data. The first programmable
computers required the programmers to write explicit instructions to directly manipulate the
hardware of the computer. This “machine language” was very tedious to write by hand since
even simple tasks such as printing some output on the screen require 10 or 20 machine language
commands. Machine language is often referred to as a “low level language” since the code
directly manipulates the hardware of the computer.

By contrast, higher level languages such as “C”, C++, Pascal, COBOL, FORTRAN,
ADA and Java are called “compiled languages”. In a compiled language, the programmer writes
more general instructions and a compiler (a special piece of software) automatically translates
these high level instructions into machine language. The machine language is then executed by
the computer. A large portion of software in use today is programmed in this fashion. We can
contrast compiled programming languages with interpreted programming languages. In an
interpreted programming language, the statements that the programmer writes are interpreted as
the program is running. This means they are translated into machine language on the fly and
then execute as the program is running. Some popular interpreted languages include Basic,
Visual Basic, Perl, Python, and shell scripting languages such as those found in the UNIX, Linux
and MacOS X environment.

We can make another comparison between two different models of programming. In


structured programming, blocks of programming statements (code) are executed one after
another. Control statements (described later on) change which blocks of code are executed next.
In object oriented programming, data are contained in objects and are accessed using special
methods (blocks of code) specific to the type of object. There is no single “flow” of the program
as objects can freely interact with one another by passing messages.

b. What is a Compiler

You write your computer program using your favourite programming language
and save it in a text file called the program file. Now let us try to get a little more detail
on how the computer understands a program written by you using a programming
language. Actually, the computer cannot understand your program directly given in the
text format, so we need to convert this program in a binary format, which can be
understood by the computer. The conversion from text program to binary file is done by
another software called Compiler and this process of conversion from text formatted
program to binary format file is called program compilation. Finally, you can execute
binary file to perform the programmed task. We are not going into the details of a
compiler and the different phases of compilation.

The following flow diagram gives an illustration of the process −

169
Figure 6.1. - illustration of the process

So, if you are going to write your program in any such language, which needs
compilation like C, C++, Java and Pascal, etc., then you will need to install their
compilers before you start programming.

c. Interpreter

We just discussed about compilers and the compilation process. Compilers are
required in case you are going to write your program in a programming language that
needs to be compiled into binary format before its execution. There are other
programming languages such as Python, PHP, and Perl, which do not need any
compilation into binary format, rather an interpreter can be used to read such programs
line by line and execute them directly without any further conversion. So, if you are
going to write your programs in PHP, Python, Perl, Ruby, etc., then you will need to
install their interpreters before you start programming.

Figure 6.1.2 - illustration of the process

d. Online Compilation

If you are not able to set up any editor, compiler, or interpreter on your machine,
then [Link] provides a facility to compile and run almost all the programs
170
online with an ease of a single click. So do not worry and let's proceed further to have a
thrilling experience to become a computer programmer in simple and easy steps.

e. Variable Declaration

Variables are place holders for data a program might use or manipulate.
Variables are given names so that we can assign values to them and refer to them later
to read the values. Variables typically store values of a given type. Types generally
include:

Integer – to store integer or “whole” numbers


Real – to store real or fractional numbers (also called float to indicate a floating point
number)
Character – A single character such as a letter of the alphabet or punctuation.
String – A collection of characters

In order to use a variable within a program, the compiler needs to know in


advance the type of data that will be stored in it. For this reason, we declare the variables
at the start of the program. Variable declaration consists of giving a new name and a data
type for the variable. This is normally done at the very start of the program.

6.2. Boolean Logic and Boolean algebra

Boolean algebra was invented by nineteenth century mathematician George Boole. In


Boolean algebra, mathematical expressions are evaluated to one of two values: True or False.
Boolean logic is the mathematical logic that is fundamental to Boolean algebra. Boolean logic
is used throughout computer science. Understanding how to pose and evaluate Boolean logic
expressions is a crucial skill for any programmer or indeed anyone who programs computers in
a formal language (such as “C”, C++, Java, Pascal, FORTRAN, SQL, etc.) or in a macro
language such as shell scripts or MS Excel formulas and macros.

This primer endeavours to introduce the topic of Boolean logic and demonstrates how it
is used in a variety of situations. Boolean logic is called a Two Valued Logic because an
expression may only take on one of two values: True or False. An expression is some collection
of logical operands and logical operators that are combined together. In arithmetic, the operands
are numbers and the operators are the familiar addition, subtraction, multiplication and division.
In Boolean logic, the operands are statements (that can be proven True or False) and the
operators are logical AND, OR and NOT.
For example, consider this expression: 4 < 6

Clearly this expression is true since the number four is less than the number 6.
As another example, consider the following statement:

I am 6 feet tall AND I am president of the United States


While it may be True that I am six feet tall (a fact that can be proven by measuring my height),
it can certainly be shown that I am not the president of the United States. Therefore, according
to Boolean logic, this entire sentence is False. Another way of saying this is: It is False that I
am 6 feet tall AND I am the president of the United States.

Consider a similar sentence:

171
I am 6 feet tall OR I am president of the United States
Notice in this case that only one of the parts of the sentence (separated by OR) need be True in
order for the entire sentence to be considered True. Another way of saying this is: It is true that
I am 6 feet tall OR I am the president of the United States.

a. The Boolean Operators

There are three Boolean operators: AND, OR and NOT. These operators are
written differently depending on the language being used. In mathematics, the logical
operators are

Written as
The following table compares how AND OR and NOT are written in different
programming languages:
Language AND OR NOT

Mathematics
“C” or C++ && || !

SQL AND OR NOT

Pascal AND OR NOT

Perl & || !

Java & || !

Basic AND OR NOT

The Boolean operators are evaluated in the following fashion. For the AND
operator, the combination of two “True” values results in “True” all other combinations
evaluate to False.
For example:
True AND True evaluates to True
True AND False evaluates to False
False AND True evaluates to False
False AND False evaluates to False
For the OR operator, as long as one of the value is True, then the expression evaluates to
True:
True OR True evaluates to True
True OR False evaluates to True
False OR True evaluates to True
False OR False evaluates to False
The NOT operator is called the “complimentary” operator. It reverses the truth value of
the operand:
NOT True evaluates to False
NOT False evaluates to True.

172
b. Comparison Operators

Boolean expressions often involve comparison operators that can be evaluated to


determine if they are True or False. Comparison operators include:

Different programming languages write these comparison operators in different ways:


Greater Less Greater than or equal Less than or equal
Language Equality than than to to Inequality

Mathematics = > <


“C” or C++ == > < >= <= !=

Pascal = > < >= <= <>

SQL = > < >= <= <>

==
or eq
Perl > or gt < or lt >= or ge <= or le != or ne
Java == > < >= <= !=

Basic = > < >= <= !=

Python == > < >= <= !=

Note for Perl language comparison of numbers uses the typical mathematical
operators. Comparison of strings uses the eq, ge, le, gt, lt and ne operators.
Comparison operators are used to form expressions that can be evaluated as True or False.
For example, we might ask if there are more than 30 students in the class using the
following expression:
Number_of_Students > 30
If there are more than 30 students in the class, then this expression will evaluate
to True. If there are 30 or fewer students in the class, then this expression will evaluate
to False. The following are more examples of these types of expressions:

Question Expression

Does Alice make more than $35,000 per year? Alice_Salary > 35000

Did the NY Giants defeat the Dallas Cowboys? Giants_Points > Cowboys_Points

Did anyone get a perfect score on the test? TestScore = 100

For each of these examples, supplying values for each of the expressions allows
us to determine if that expression is True or False. For example, if Alice only makes
$31,000, then the first expression would evaluate to False.

173
c. Combining Boolean and Comparison Operators

In the previous sections, we have seen how the Boolean operators and
Comparison operators can be used to form expressions. In this section, we combine the
two types of operators to form more complex expressions.
For example, suppose we ask the question: Are there more than 30 students in the class,
and are there more than 30 seats in the room? This might be expressed as:
Number_of_Students > 30 AND Number_of_Seats > 30

We evaluate such an expression by determining the value (True or False) of each


of the comparison expressions, and then use those values to evaluate the Boolean
expression. In our example, suppose the class is a very large one that is held in a large
room. In other words, there are more than 30 students and the room has more than 30
seats. Therefore, we would evaluate the expression as follows:
The Number_of_Students > 30 portion of the expression evaluates to True.
The Number_of_Seats > 30 portion of the expression evaluates to True.
Substituting those values in the expression give us:
True AND True
The True AND True expression evaluates to True as can be seen in the Truth tables
for the AND operator.
Therefore, we conclude that the entire expression evaluates to True.
The following example expressions are based on these assumptions:
All employees belong to a department
All employees working in department 5 have salaries greater than $25,000
All employees in department 4 make exactly $40,000 per year.
Alice is an employee and she works in department 5
Bill is an employee and he works in department 4
Given the above 5 items are facts, consider the truth values of the following expressions:
Expression Evaluation

Alice_salary < 25000 is False


Alice_salary < 25000 AND Alice_Department = Alice_Department = 5 is True
5 False AND True is False

Alice_salary < 25000 is False


NOT Alice_salary < 25000 NOT False is True

Alice_salary < 25000 is False


Bill_Salary = 40000 is True
Alice_salary < 25000 OR Bill_Salary = 40000 False OR True is True

Alice_salary > 25000 is True


Bill_Salary < 40000 is False
Alice_salary > 25000 AND NOT Bill_Salary < NOT False is True
40000 True AND True is True

174
As an exercise, evaluate the following expressions:
Expression Evaluation
Alice_salary < 25000 OR
Alice_Department = 4

Alice_salary >= 25000 AND


Bill_department = 4

Alice_salary < 25000 OR


Bill_Salary < 40000 OR
Alice_Department = 5

NOT ( Alice_salary > 25000 AND


Bill_Salary < 40000 )

Alice_salary < 25000 AND


( Bill_Salary <= 40000 OR
Alice_Department = 5 )

Notice in the last two cases, parenthesis may be used to group portions of the
expression. In general Boolean expressions are evaluated from left to right except where
parenthesis change the order. In the third example above, notice that when multiple
conditions are separated by OR, it only takes one of the conditions to be True in order
to cause the entire expression to evaluate to True.

d. Conditional Statements

What makes programming so much more powerful are conditional statements?


This is the ability to test a variable against a value and act in one way if the condition is
met by the variable or another way if not. They are also commonly called by
programmers if statements. To know if a condition is True of False, we need a new type
of data: The Booleans. They allow logical operations. A logic statement or operation can
be evaluated to be true or False. Our conditional statement can then be understood like
this:
If (a condition evaluates to True):
Then do these things only for ‘True’
Else:
Otherwise do these things only for ‘False’.
The condition can be anything that evaluates as True or False. Comparisons always
return True or False, for example == (equal to), > (greater than), < (less than.)
The else part is optional. If you leave it off, nothing will happen if the conditional
evaluates to ‘False’.

6.3 Systems Analysis and Design

SAD stands for Systems Analysis and Design and it is a process of identifying, analyzing,
designing and implementing computer-based information systems that will suit a particular
business. It entails identifying the information requirements of an organization and then creating
systems that can address the needs and challenges of an organization to improve its operations.

175
6.3.1 Introduction to Software Development Approaches

Software development methods are optimal paths in systematic management of


development of a software system.

(a) Waterfall Method

• An approach to the design of the research where one phase has to


be executed before the next one commences.

• They are Requirements, Design, Implementation, Testing,


Deployment, and Maintenance.

• Example: Designing a system where it is possible to have a clearly


thought-out system, where all the needs are stipulated at the initial stages
and each process is carried out systematically.

(b) Agile Methods

• An adaptive, fluid process that encourages communication, change


and small and frequent deliveries of change.

• Emphasizes on feedback from the customers, with more frequent


delivery of the working release.

• Example: Constantly creating an internet store where features are


introduced in brief bursts, meaning features may be modified on a daily
basis thanks to the users.

6.4 Types of Requirements

6.4.1 Functional Requirements

• It is important to state what must be accomplished by the system. They


refer to certain actions and purposes.

• Example: “It should be possible to use a username and password in order


to log into the system.”

6.4.2 Non-functional Requirements

• Describe how the system accomplishes the function or task saying


something like how well it performs the function, its security level, the ease of
using it etc.

• Example: “It should take the system not more than 2seconds to call up the
login page.”

6.5 Requirements Gathering Techniques

6.5.1 Interviews
176
• This means using face to face communications to investors to get detailed
information from them.

• Example: Identifying from the department heads the reporting capabilities


and requirements that the system should meet.

6.5.2 Observations

• Observing the existing systems and how the users engage with them in
order to map the utility and efficiency of the system.

• Example: Sitting in a local restaurant to watch customer service


representatives so that a more efficient helpdesk could be developed.

6.5.3 Questionnaires

• Using questionnaires in the form of a set of written questions in order to


gather information from numerous members of the stakeholders group.

• Example: An email, which can be completed by an online questionnaire,


to the employees aimed at receiving their opinion regarding the existing internal
communication application.

6.5.3 Report Review

• By going through the available documentations and reports in search of


information.

• Example: Identifying data support needs for a sales tracking system by


analyzing sales reports prepared on yearly basis.

6.6 Tool Requirement Specification (TRS)

6.6.1 Purpose

SRS document provides all-inclusive description and specification of the


complete software requirements which is used as a contract between SSW and the
stakeholders.

6.6.2 Basic Characteristics of SRS

• Complete: It has to encompass all feature and quality that a product is


required to have.

• Unambiguous: These include using language which is freely


understandable and one whose connotations are well understood.

• Verifiable: The requirements should be assuming this is the case then the
following attributes should characterize the requirements;

177
• Example: An SRS of a library management system where every aspect of
the system is described right from the login module of the user to the process of
cataloging the books.

6.7 Types of System Design Methodologies

6.7.1 Object-Oriented Analysis and Design (OOAD) with UML

Use Case Diagram

 A graphical representation showing how users (actors) interact with the


system to achieve a goal.
 Example: A use case diagram for an ATM system showing user
interactions for checking balance, withdrawing cash, and depositing funds.

Class Diagram

 A diagram showing the system's classes, their attributes, methods, and


relationships.
 Example: In a hospital management system, a class diagram could include
Doctor, Patient, and Appointment classes.

6.7.2 Structured System Analysis and Design (SSAD) with DFD

Level 0 (Context Level Diagram)

 The highest-level diagram showing the system as a whole and its


interactions with external entities.
 Example: A level 0 DFD for a bank system showing how the bank interacts
with customers and financial institutions.

Level 1 (Top-Level Diagram)

 A detailed breakdown of the system’s major processes.


 Example: A level 1 DFD for the same bank system showing processes such
as account management, loan processing, and transaction handling.

Level 2 Diagram

 A further breakdown of Level 1 processes.


 Example: Breaking down the "Account Management" process into sub-
processes like opening an account, closing an account, and updating account
information.

6.8 Introduction to Software Testing Techniques

6.8.1 Unit Testing

 Testing individual components or units of the software to ensure they work


as intended.
 Example: Testing the login function of a website.
178
6.8.2 Integration Testing

 Testing how different modules or units work together.


 Example: Testing the interaction between the login module and the user
profile module.

6.8.3 System Testing

 Testing the entire system as a whole to ensure it meets the specified


requirements.
 Example: Running the entire e-commerce platform to ensure all features
(login, product search, checkout) work as expected.

6.8.4 Acceptance Testing

 Testing the system with the user to confirm it satisfies business needs.
 Example: A business conducting tests on a new inventory system before
final deployment

6.9 Writing Test Cases

 A test case is a set of actions performed to verify a particular feature or


functionality of the software.
 Example of a test case for a login page:
o Test Case ID: TC001
o Test Scenario: Test login functionality
o Test Steps:
1. Navigate to the login page.
2. Enter a valid username and password.
3. Click the login button.
o Expected Result: User is redirected to the dashboard.

6.10. C#.Net

a. Introduction to C#

C# is a modern, general-purpose, object-oriented programming language


developed by Microsoft and approved by European Computer Manufacturers
Association (ECMA) and International Standards Organization (ISO). C# was
developed by Anders Hejlsberg and his team during the development of .Net
Framework. C# is designed for Common Language Infrastructure (CLI), which consists
of the executable code and runtime environment that allows use of various high-level
languages on different computer platforms and architectures.

The following reasons make C# a widely used professional language:

• It is a modern, general-purpose programming language


• It is object oriented.
• It is component oriented.
• It is easy to learn.
179
• It is a structured language.
• It produces efficient programs.
• It can be compiled on a variety of computer platforms.
• It is a part of .Net Framework.

b. Strong Programming Features of C#

Although C# constructs closely follow traditional high-level languages, C and


C++ and being an object-oriented programming language. It has strong resemblance
with Java, it has numerous strong programming features that make it endearing to a
number of programmers worldwide.

Following is the list of few important features of C#:

• Boolean Conditions
• Automatic Garbage Collection
• Standard Library
• Assembly Versioning
• Properties and Events
• Delegates and Events Management
• Easy-to-use Generics
• Indexers Conditional Compilation
• Simple Multithreading
• LINQ and Lambda Expressions
• Integration with Windows

c. Programming Environment

In this chapter, we will discuss the tools required for creating C# programming.
We have already mentioned that C# is part of .Net framework and is used for writing
.Net applications. Therefore, before discussing the available tools for running a C#
program, let us understand how C# relates to the .Net framework.

d. The .Net Frame work

The .Net framework is a revolutionary platform that helps you to write the
following types of applications:

• Windows applications
• Web applications
• Web services

The .Net framework applications are multi-platform applications. The


framework has been designed in such a way that it can be used from any of the following
languages: C#, C++, Visual Basic, Jscript, COBOL, etc. All these languages can access
the framework as well as communicate with each other. The .Net framework consists of
an enormous library of codes used by the client languages such as C#. Following are
some of the components of the .Net framework:

180
• Common Language Runtime (CLR)
• The .Net Framework Class Library
• Common Language Specification
• Common Type System
• Metadata and Assemblies
• Windows Forms
• [Link] and [Link] AJAX
• [Link]
• Windows Workflow Foundation (WF)
• Windows Presentation Foundation
• Windows Communication Foundation (WCF)
• LINQ

For the jobs each of these components perform, please see [Link] -
Introduction, and for details of each component, please consult Microsoft's
documentation.

e. Integrated Development Environment (IDE) for C#

Microsoft provides the following development tools for C# programming:

• Visual Studio 2010 (VS)


• Visual C# 2010 Express (VCE)
• Visual Web Developer

The last two are freely available from Microsoft official website. Using
these tools, you can write all kinds of C# programs from simple command-line
applications to more complex applications. You can also write C# source code
files using a basic text editor like Notepad, and compile the code into assemblies
using the command-line compiler, which is again a part of the .NET Framework.

Visual C# Express and Visual Web Developer Express edition are


trimmed down versions of Visual Studio and has the same appearance. They
retain most features of Visual Studio. In this tutorial, we have used Visual C#
2010 Express. You can download it from Microsoft Visual Studio. It gets
installed automatically on your machine.

Note: You need an active internet connection for installing the express edition.

These notes provide a comprehensive overview of systems analysis and


design, along with examples to illustrate each concept.

6.11. Commonly Available Software and Their Suitability:

6.11.1 Integrated Development Environments (IDEs):

 Visual Studio: Comprehensive IDE suitable for various languages (C#,


C++, [Link]) and provides tools for debugging and design.

181
 Eclipse: Popular for Java development but also supports other languages
through plugins.
 PyCharm: Best for Python development, offering excellent features for
code completion, debugging, and testing.
 NetBeans: IDE supporting Java, PHP, and HTML5, known for its ease
of use and versatility.

Suitability Examples:

 Visual Studio for building a C# Windows Forms application.


 PyCharm for developing a Python desktop application using Tkinter.

6.12 Programming Fundamentals

 Structured Programming: Emphasizes linear flow of control with functions


and procedures.
o Example: A simple C program using functions to perform arithmetic
operations.
 Object-Oriented Programming (OOP): Uses objects and classes to model
real-world entities and interactions.
o Example: A Python class Car with attributes like make and model and
methods like start() and stop().

Data Types and Variables:

 Data Types: Integer, Float, Char, String, Boolean.


o Example: int age = 25; in C++ or age = 25 in Python.
 Variables: Named storage locations for data.
o Example: let score = 100; in JavaScript.

Coding Standards and Naming Conventions:

 Standards: Write readable and maintainable code.


 Naming Conventions:
o CamelCase: myVariableName
o snake_case: my_variable_name
o PascalCase: MyClassName

Operators:

 Arithmetic Operators: +, -, *, /
o Example: total = price * quantity;
 Logical Operators: && (AND), || (OR), ! (NOT)
o Example: if (age > 18 && citizen)

Control Structures:

 If-Else Statements:
o Example: if (temperature > 30) { /* code */ }
 Loops: for, while, do-while
o Example: for (int i = 0; i < 10; i++) { /* code */ }
182
Functions (Built-in and User-Defined):

 Built-in Functions: print(), len()


o Example: print("Hello World")
 User-Defined Functions:
o Example:

Procedures:

 Similar to functions but do not return a value.


o Example: A procedure in Pascal:

Modules:

 Definition: Files containing Python code that can be imported.


o Example: import math to use mathematical functions.

Develop Programs Using IDE

 Creating a Project:
o Example: In Visual Studio, create a new C# Windows Forms
Application project.
 Writing Code:
o Example: Implement a login form with fields for username and
password.
 Debugging:
o Example: Set breakpoints and use step-through debugging in PyCharm.

6.13. Create a simple C# console app in Visual Studio

Create a project

To start, create a C# application project. The project type comes with all the template files
you need.

1. Open Visual Studio, and select Create a new project in the Start window.

183
2. In the Create a new project window, select All languages, and then
choose C# from the dropdown list. Choose Windows from the All-platforms list, and
choose Console from the All-project types list.

After you apply the language, platform, and project type filters, choose
the Console App template, and then select Next.

3. In the Configure your new project window, type or enter Calculator in


the Project name box, and then select Next.

184
4. In the Additional information window, select .NET 8.0 for the Target
Framework field. Then, select Create.

Explore integer math

Start with some basic integer math in C#.

1. In Solution Explorer, in the right pane, select [Link] to display the file in
the code editor
2. In the code editor, replace the default "Hello World" code that
says [Link]("Hello World!");.

185
6.14 Developing Desktop Applications
Developing Desktop Applications refers to the process of creating software programs that
run on a desktop or laptop computer, rather than on a web server or mobile device. This involves
designing, coding, testing, and deploying applications that provide users with a graphical
interface and are installed locally on their operating system. These applications can range from
simple tools to complex systems and typically require an understanding of programming
languages, user interface design, and interaction with the underlying operating system and
hardware.

6.12.1 Create a Windows Forms app in Visual Studio with C#

Create a project

First, create a C# application project. The project type comes with


all the template files you need to create your application.

1. Open Visual Studio.


2. On the start window, select Create a new project.

186
3. In Create a new project, select the Windows Forms App (.NET
Framework) template for C#.

You can refine your search to quickly get to the template you
want. For example, type Windows Forms App in the search box. Next,
select C# from the language list, and then select Windows from the
platform list.

4. In the Configure your new project window, in Project name,


enter HelloWorld, and select Create.

187
Visual Studio opens your new project.

Create the application

After you select your C# project template and name your project, Visual
Studio opens a form for you. A form is a Windows user interface. Create a Hello
World application by adding controls to the form. Then run the app.

Add a button to the form

1. Select Toolbox to open the Toolbox flyout window.

If you don't see the Toolbox option, you can open it from the menu bar.
Select View > Toolbox or Ctrl+Alt+X.

2. Expand Common Controls and select the Pin icon to dock


the Toolbox window.

188
3. Select the Button control and then drag it onto the form.

4. In the Properties window, locate Text. Change the name


from button1 to Click this, and then select Enter.

If you don't see the Properties window, you can open it from the menu bar.
Select View > Properties Window or F4.

189
5. In the Design section of the Properties window, change the name
from button1 to btnClickThis, and then select Enter.

Add a label to the form

After you add a button control to create an action, add a label control to send text to.

1. Select the Label control from the Toolbox. Then drag it onto the form and
drop it beneath the Click this button.
2. In either the Design section or the (DataBindings) section of
the Properties window, change the name of label1 to lblHelloWorld. Then
select Enter.

Add code to the form

1. In the [Link] [Design] window, double-click the Click this button to open
the [Link] window.

Alternatively, you can expand [Link] in Solution Explorer, and then


choose Form1.

2. In the [Link] window, after the private void line, type or


enter [Link] = "Hello World!"; as shown in the following screenshot.

190
3. Run the application

1. Select the Start button to run the application.

2. Several things happen. In the Visual Studio IDE, the Diagnostics Tools window
opens, and an Output window opens, too. But outside of the IDE, a Form1 dialog box
appears. It includes your Click this button and text that says label1.

3. Select the Click this button in the Form1 dialog box. Notice that the label1 text
changes to Hello World!

191
4. Close the Form1 dialog box to stop running the app.

6.15 Connecting a Database to the Developed Program

Write Code for Insert/Update/Delete/Select Operations:

 Insert Example (SQL):

 Update Example (SQL):

 Delete Example (SQL):

 Select Example (SQL):

Database Connection Example (Python with SQLite):

192
6.16 Test the Developed Program Using the Test Cases Written

 Writing Test Cases:


o Example: Testing a login function.

 Running Tests:
o Example: Use pytest for running test cases in Python.

12.6 Deploy the Developed Software

 Packaging the Application:


o Example: Using PyInstaller to package a Python application into an
executable.

 Distributing the Software:


o Example: Creating an installer using Inno Setup for a Windows
application.

193
6.17 Designing Static Websites

 Static Web Page: A web page that displays fixed content to all users, created
with HTML and CSS. It does not change unless manually updated.
 Web Designing Tools: Software used for creating and editing web pages,
including text editors (e.g., Visual Studio Code), design tools (e.g., Adobe
Photoshop), and development tools (e.g., browser developer tools).
 Site Map: A diagram that outlines the structure of a website, showing all pages
and their relationships.
 Navigation Structures: The way users move through a website, including top
navigation bars, sidebars, and footer menus.
 HTML (Hypertext Markup Language): The standard language for creating web
pages. It structures content using elements such as headings, paragraphs, links, and
forms.
 CSS (Cascading Style Sheets): A stylesheet language used to control the layout
and appearance of web pages. CSS can be applied inline, internally, or externally.
 Embedding Media: Incorporating objects like images, videos, and audio into
web pages using HTML tags.

These definitions provide a basic understanding of static website design concepts and
practices.

6.18 Introduction to Web Designing


What is a Web Page / Website

 Web Page: A document on the World Wide Web, often written in HTML,
displayed in a web browser.
 Website: A collection of related web pages under a single domain name, linked
together to provide a cohesive experience.

Difference Between Static and Dynamic Web Page

 Static Web Page: Displays the same content to every visitor. Created with HTML
and CSS only, and does not change unless manually updated.
 Dynamic Web Page: Content can change based on user interaction or other
factors. Requires server-side scripting languages like PHP or JavaScript.

Web Designing Tools

 Text Editors: Notepad++, Sublime Text, Visual Studio Code.


 Design Tools: Adobe Photoshop, Figma, Sketch.
 Development Tools: Web browsers (Chrome DevTools), version control systems
(Git).

Web Designing Best Practices

 Responsive Design: Ensures the website looks good on all devices.


 Accessibility: Make the website usable for people with disabilities.
 Performance Optimization: Optimize images and code to enhance loading
times.
 SEO: Structure your site and use keywords to improve search engine ranking.
194
6.18.1 Identify Website Requirements

 Purpose: Determine the main goal of the website (e.g., information, sales,
portfolio).
 Target Audience: Understand who will use the website and their needs.
 Content: Decide what content will be displayed (text, images, videos).
 Functionality: Identify any required features (forms, contact info, navigation).

Example: For a small business website, requirements might include a homepage, services
page, contact form, and a gallery of products.

6.18.2 Develop Web Page Layout


Site Map

 Definition: A visual or textual representation of the website’s structure,


showing all the pages and their relationships.
 Purpose: Helps plan and organize the content and navigation.

Example: A site map for an e-commerce site might include Home, Products, About
Us, Contact, and Blog.

6.18.3 The Navigation Structures

 Definition: The way users move through a website, including menus,


links, and buttons.
 Types:
o Top Navigation: Main menu at the top of the page.
o Sidebar Navigation: Menu on the side of the page.
o Footer Navigation: Links at the bottom of the page.

Example: An online store might have a top navigation bar with links to Home,
Shop, Cart, and Account.

6.19 HTML (Hypertext Markup Language)


6.19.1 Introduction to HTML

Definition: The standard language for creating web pages. HTML structures the
content on the page.

6.19.2 HTML Elements

 Tags: Basic building blocks of HTML. Examples include <h1>, <p>,


<a>, <div>, <img>.
 Attributes: Provide additional information about elements. For example,
<a href="url">Link</a>

Example:

195
6.19.3 HTML Forms

 Definition: Allows users to submit data to a server.


 Elements: <form>, <input>, <textarea>, <button>, <select>.

Example:

6.19.4 Use Hyperlinks

 Definition: Links that connect to other web pages or resources.


 Syntax: <a href="url">Link Text</a>.

Example:

6.19.5 CSS (Cascading Style Sheets)


Introduction to CSS

Definition: A style sheet language used to describe the presentation of a


web page written in HTML. CSS controls the layout, colors, fonts, and overall
look.

CSS Syntax

Structure: Selectors and declarations.


196
Example:

Example:

CSS Apply Methods

 Inline: CSS applied directly within an HTML element using the style attribute.

 Internal: CSS written within a <style> tag in the HTML document's <head>.

 External: CSS stored in a separate .css file linked to the HTML document.

Embed Different Objects/Media to Web Page

 Images: Use <img> tag to include images.

 Videos: Use <video> tag to embed video content.

197
 Audio: Use <audio> tag for sound files.

 Other Embeds: Embed objects like PDFs using the <embed> or <object> tag.

These notes provide a structured approach to designing static websites, covering the
essential concepts and practical examples for each topic.

6.20 How to Create a website using HTML And CSS

In this section, let’s create a full-fledged website using only HTML and CSS. Most of the
users have a question today – Can you create a website just using HTML and CSS?
It is quite possible to create a good-looking website with the help of only HTML and CSS. HTML
stands for Hypertext markup language and provides the skeleton for our website. However, CSS
(Cascading Style Sheet) allows the skeleton to be better-looking. Let us use seven steps to create
a good-looking website from scratch.

Step 1: Create a Layout


First create a basic structure of your website as a rough sketch. There are a lot of free
online services that will help you design your website. Nonetheless, you must have a basic
structure of the website ready.

198
Step 2: Set up the boiler code
Create a new project folder and create an empty [Link] file inside the folder. Here,
add the boilerplate code to the HTML file.

<!DOCTYPE html>

<html lang="en">

<head>

<title>How to create a website using HTML and CSS</title>

<link rel="stylesheet" href="css/[Link]">

199
</head>

<body>

<h1>Test</h1>

</body>

</html>

Before starting the actual content add some test content in your HTML file, and run it on
the browser to test if the code is working fine.

Step 3: Create major elements in the layout


Create section elements in the HTML file.
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>How to create a website using HTML and CSS</title>

<link rel="stylesheet" href="css/[Link]">

</head>

<body>

<header>

/header>

<main>

<section id="intro">

200
</section>

<section id="about">

</section>

<section id="contact">

</section>

</main>

<footer>

</footer>

</body>

</html>

Step 4: Create the HTML content


In the previous step, you had created the elements in the layout. In this step, fill in the
HTML content. Note that, in this example, let us fill the content with dummy text only.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How to create a website using HTML and CSS</title>
<link rel="stylesheet" href="css/[Link]">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="#intro">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="intro">
<div class="Container">
<img src="Images/[Link]" alt="display picture of doggo">
<h2>My name is Doggo</h2>
</div>
201
</section>

<section id="about">
<div class="container">
<h1>About Me</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sint, similique?</p>
<ul>
<li>Btech Qualified</li>
<li>Software Engineer</li>
<li>GATE AIR 01</li>
</ul>
</div>
</section>
<section id="contact">
<div class="container">
<h1>Contact me</h1>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nam, laudantium.</p>
<ul>
<li>Email ID</li>
<li>Insta ID</li>
<li>Facebook ID</li>
</ul>
</div>
</section>
</main>
<footer>
<p>© Copyright 2022 Doggo Co LTd.</p>
</footer>
</body>
</html>

Now, if you reload the page, you are going to get an output something like this. You are
now going to give this webpage some CSS in the next step to make it good-looking.

202
Step 5: Create CSS for the layout
Before adding the depth in the CSS, let us first add some basic CSS to make our webpage
look somewhat similar to the layout that we designed in the first step.
Moreover, we linked our HTML file to a CSS file in the second step while writing our boilerplate
code. Add the basic layout CSS in the linked CSS file. In this step, we are going to focus on
height, width, padding, margin, and display of the sections and images, to make them adjustable
according to the webpage.

*{
padding: 0;
margin: 0;
}

header{
203
height: 45px;
}
header nav ul{
display: flex;
margin-left: 80%;
}

header nav ul li{


padding-left: 10%;
}

section{
height: 100vh;
border: 1px solid grey;
display: flex;
justify-content: center;
align-items: center;
}

.Container{
margin-top: 10%
}

.Container img{
height: 300px;
}

.Container h2{
margin-top: 3%;
}

footer {
line-height: 40px;
display: flex;
justify-content: center;
}

Step 6: Create CSS to style individual elements


In this step let us style individual content. Let us focus on properties like font, border,
colors, and more.

*{
padding: 0;
margin: 0;
}

header{
height: 45px;
}
204
header nav ul{
display: flex;
margin-left: 70%;
list-style: none;
}

header nav ul li{


padding-left: 10%;
}

header a{
text-decoration: none;
color: brown;

section{
height: 100vh;
border: 1px solid grey;
display: flex;
justify-content: center;
align-items: center;
}

.Container img{
height: 300px;
border-radius: 50%;
}

.Container h2{
margin-top: 2%;
font-size: 3em;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode',
Geneva, Verdana, sans-serif;
}
.Container p, ul{
margin-top: 2%;
font-size: 1.5rem;
}

footer {
line-height: 40px;
display: flex;
justify-content: center;
font-size: 1rem;
}

Step 7: Add background color and style


In this step, let us add some finishing touches, and our website is ready. Let us add a
background image and background colors to the sections.
205
#intro {
background-image: url([Link]);
background-repeat: round;
}
#about{
background-color: bisque;
}
#contact{
background-color: blanchedalmond;
}

After completing the entire code of our website, it will look something like this. Note
that you can add more CSS to make it further good-looking.

206
6.21 Introduction to Python

Python is a very popular general-purpose interpreted, interactive, object-oriented, and


high-level programming language. Python is dynamically-typed and garbage-collected
programming language. It was created by Guido van Rossum during 1985- 1990. Like Perl,
Python source code is also available under the GNU General Public License (GPL).

Python supports multiple programming paradigms, including Procedural, Object


Oriented and Functional programming language. Python design philosophy emphasizes code
readability with the use of significant indentation.

207
6.21.1 Why to Learn Python?
Python is consistently rated as one of the world's most popular programming
languages. Python is fairly easy to learn, so if you are starting to learn any programming
language then Python could be your great choice. Today various Schools, Colleges and
Universities are teaching Python as their primary programming language. There are many
other good reasons which makes Python as the top choice of any programmer:

 Python is Open Source which means its available free of cost.


 Python is simple and so easy to learn
 Python is versatile and can be used to create many different things.
 Python has powerful development libraries include AI, ML etc.
 Python is much in demand and ensures high salary
Python is a MUST for students and working professionals to become a great
Software Engineer specially when they are working in Web Development Domain. I will
list down some of the key advantages of learning Python:

 Python is Interpreted − Python is processed at runtime by the


interpreter. You do not need to compile your program before executing it. This
is similar to PERL and PHP.
 Python is Interactive − You can actually sit at a Python prompt and
interact with the interpreter directly to write your programs.
 Python is Object-Oriented − Python supports Object-Oriented style or
technique of programming that encapsulates code within objects.
 Python is a Beginner's Language − Python is a great language for the
beginner-level programmers and supports the development of a wide range of
applications from simple text processing to WWW browsers to games.

6.22 Characteristics of Python

Following are important characteristics of Python Programming −

 It supports functional and structured programming methods as well as OOP.


 It can be used as a scripting language or can be compiled to byte-code for
building large applications.
 It provides very high-level dynamic data types and supports dynamic type
checking.
 It supports automatic garbage collection.
 It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.

6.23 Applications of Python

Python is a general-purpose programming language known for its readability. It is widely


applied in various fields.
 In Data Science, Python libraries like Numpy, Pandas, and Matplotlib are used
for data analysis and visualization.
 Python frameworks like Django, and Pyramid, make the development and
deployment of Web Applications easy.

208
 This programming language also extends its applications to computer vision and
image processing.
 It is also favored in many tasks like Automation, Job Scheduling, GUI
development, etc.

6.24 Features of Python

The latest release of Python is 3.x. As mentioned before, Python is one of the most widely
used language over the web. I'm going to list few of them here:

 Easy-to-learn − Python has few keywords, simple structure, and a clearly defined
syntax. This allows the student to pick up the language quickly.
 Easy-to-read − Python code is more clearly defined and visible to the eyes.
 Easy-to-maintain − Python's source code is fairly easy-to-maintain.
 A broad standard library − Python's bulk of the library is very portable and
cross-platform compatible on UNIX, Windows, and Macintosh.
 Interactive Mode − Python has support for an interactive mode which allows
interactive testing and debugging of snippets of code.
 Portable − Python can run on a wide variety of hardware platforms and has the
same interface on all platforms.
 Extendable − You can add low-level modules to the Python interpreter. These
modules enable programmers to add to or customize their tools to be more efficient.
 Databases − Python provides interfaces to all major commercial databases.
 GUI Programming − Python supports GUI applications that can be created and
ported to many system calls, libraries and windows systems, such as Windows MFC,
Macintosh, and the X Window system of Unix.
 Scalable − Python provides a better structure and support for large programs than
shell scripting.
6.25 Pythonic Code Style
Python leaves you free to choose to program in an object-oriented, procedural, functional,
aspect-oriented, or even logic-oriented way. These freedoms make Python a great language to
write clean and beautiful code.
Pythonic Code Style is actually more of a design philosophy and suggests to write a code which
is :
 Clean
 Simple
 Beautiful

209
 Explicit
 Readable
6.26 Evolution of Python – The Major Python Versions
Following are the important stages in the history of Python −
Python 0.9.0
Python's first published version is 0.9. It was released in February 1991. It consisted of
features such as classes with inheritance, exception handling, and core data types like lists and
dictionaries.
Python 1.0
In January 1994, version 1.0 was released, armed with functional programming tools,
features like support for complex numbers etc and module system which allows a better code
organization and reuse.
Python 2.0
Next major version − Python 2.0 was launched in October 2000. Many new features such
as list comprehension, garbage collection and Unicode support were included with it.
Throughout the 2000s, Python 2.x became the dominant version, gaining traction in industries
ranging from web development to scientific research. Various useful libraries like like NumPy,
SciPy, and Django were also developed.
Python 3.0
Python 3.0, a completely revamped version of Python was released in December 2008.
The primary objective of this revamp was to remove a lot of discrepancies that had crept in
Python 2.x versions. Python 3 was backported to Python 2.6. It also included a utility named
as python2to3 to facilitate automatic translation of Python 2 code to Python 3. Python 3
provided new syntax, unicode support and Improved integer division.
EOL for Python 2.x
Even after the release of Python 3, Python Software Foundation continued to support the
Python 2 branch with incremental micro versions till 2019. However, it decided to discontinue
the support by the end of year 2020, at which time Python 2.7.17 was the last version in the
branch.
Current Version of Python
Meanwhile, more and more features have been incorporated into Python's 3.x branch. As
of date, Python 3.11.2 is the current stable version, released in February 2023.

210
6.27 Python's most important features are as follows:

1. Easy to Learn
This is one of the most important reasons for the popularity of Python. Python has a
limited set of keywords. Its features such as simple syntax, usage of indentation to avoid clutter
of curly brackets and dynamic typing that doesn't necessitate prior declaration of variable help a
beginner to learn Python quickly and easily.

2. Dynamically Typed
Python is a dynamically typed programming language. In Python, you don't need to
specify the variable time at the time of the variable declaration. The types are specified at the
runtime based on the assigned value due to its dynamically typed feature.
3. Interpreter Based
Instructions in any programming languages must be translated into machine code for the
processor to execute them. Programming languages are either compiler based or interpreter
based.
In case of a compiler, a machine language version of the entire source program is generated. The
conversion fails even if there is a single erroneous statement. Hence, the development process is
tedious for the beginners. The C family languages (including C, C++, Java, C# etc) are compiler
based.
4. Interactive
Standard Python distribution comes with an interactive shell that works on the principle
of REPL (Read – Evaluate – Print – Loop). The shell presents a Python prompt >>>. You can

211
type any valid Python expression and press Enter. Python interpreter immediately returns the
response and the prompt comes back to read the next expression.

5. Multi-paradigm
Python is a completely object-oriented language. Everything in a Python program is
an object. However, Python conveniently encapsulates its object orientation to be used as an
imperative or procedural language – such as C. Python also provides certain functionality that
resembles functional programming. Moreover, certain third-party tools have been developed to
support other programming paradigms such as aspect-oriented and logic programming.
6. Standard Library
Even though it has a very few keywords (only Thirty-Five), Python software is
distributed with a standard library made of large number of modules and packages. Thus, Python
has out of box support for programming needs such as serialization, data compression, internet
data handling, and many more. Python is known for its batteries included approach.
Some of the Python's popular modules are:
 NumPy
 Pandas
 Matplotlib
 Tkinter
 Math
7. Open Source and Cross Platform
Python is a cross-platform language. Pre-compiled binaries are available for use on
various operating system platforms such as Windows, Linux, Mac OS, Android OS. The
reference implementation of Python is called CPython and is written in C. You can download
the source code and compile it for your OS platform.
A Python program is first compiled to an intermediate platform independent byte code. The
virtual machine inside the interpreter then executes the byte code. This behaviour makes Python
a cross-platform language, and thus a Python program can be easily ported from one OS platform
to other.
212
8. GUI Applications
Python's standard distribution has an excellent graphics library called TKinter. It is a
Python port for the vastly popular GUI toolkit called TCL/Tk. You can build attractive user-
friendly GUI applications in Python. GUI toolkits are generally written in C/C++. Many of them
have been ported to Python. Examples are PyQt, WxWidgets, PySimpleGUI etc.
9. Database Connectivity
Almost any type of database can be used as a backend with the Python application. DB-
API is a set of specifications for database driver software to let Python communicate with a
relational database. With many third-party libraries, Python can also work with NoSQL
databases such as MongoDB.
10. Extensible
The term extensibility implies the ability to add new features or modify existing features.
As stated earlier, CPython (which is Python's reference implementation) is written in C. Hence
one can easily write modules/libraries in C and incorporate them in the standard library. There
are other implementations of Python such as Jython (written in Java) and IPython (written in
C#). Hence, it is possible to write and merge new functionality in these implementations with
Java and C# respectively.
11. Active Developer Community
As a result of Python's popularity and open-source nature, a large number of Python
developers often interact with online forums and conferences. Python Software Foundation also
has a significant member base, involved in the organization's mission to "Promote, Protect, and
Advance the Python Programming Language"
Python also enjoys a significant institutional support. Major IT companies Google, Microsoft,
and Meta contribute immensely by preparing documentation and other resources.

213
6.28 Difference between Python and C++

6.29 Hello World Program in Python


Printing "Hello World" is the first program in Python. This program will not take any
user input, it will just print text on the output screen. It is used to test if the software needed to
compile and run the program has been installed correctly.
Steps
The following are the steps to write a Python program to print Hello World –

 Step 1: Install Python. Make sure that Python is installed on your system or not.
 Step 2: Choose Text Editor or IDE to write the code.
 Step 3: Open Text Editor or IDE, create a new file, and write the code to print
Hello World.
 Step 4: Save the file with a file name and extension ".py".
214
 Step 5: Compile/Run the program.

In the above code, we wrote two lines. The first line is the Python comment that
will be ignored by the Python interpreter, and the second line is the print() statement that
will print the given message ("Hello World") on the output screen.
Output

Different Ways to Write and Execute Hello World Program


Using Python Interpreter Command Prompt Mode
It is very easy to display the Hello World message using the Python interpreter. Launch
the Python interpreter from a command terminal of your Windows Operating System and
issue the print statement from the Python prompt as follows −
Example

Similarly, Hello World message is printed on Linux System.


Example

6.30 Python Interpreter


Python is an interpreter-based language. In a Linux system, Python's executable is
installed in /usr/bin/ directory. For Windows, the executable ([Link]) is found in the
installation folder (for example C:\python311).

This tutorial will teach you How Python Interpreter Works in interactive and scripted
mode. Python code is executed by one statement at a time method. Python interpreter has two

215
components. The translator checks the statement for syntax. If found correct, it generates an
intermediate byte code. There is a Python virtual machine which then converts the byte code in
native binary and executes it. The following diagram illustrates the mechanism:

Python interpreter has an interactive mode and a scripted mode.

6.30.1 Python Interpreter - Interactive Mode


When launched from a command line terminal without any additional options, a
Python prompt >>> appears and the Python interpreter works on the principle of REPL
(Read, Evaluate, Print, Loop). Each command entered in front of the Python prompt is
read, translated and executed. A typical interactive session is as follows.

To close the interactive session, enter the end-of-line character (ctrl+D for Linux
and ctrl+Z for Windows). You may also type quit() in front of the Python prompt and
press Enter to return to the OS prompt.

The interactive shell available with standard Python distribution is not equipped
with features like line editing, history search, auto-completion etc. You can use other
advanced interactive interpreter software such as IPython and bpython to have
additional functionalities.

216
6.30.2 Python Interpreter - Scripting Mode
Instead of entering and obtaining the result of one instruction at a time as in the
interactive environment, it is possible to save a set of instructions in a text file, make sure
that it has .py extension, and use the name as the command line parameter for Python
command.
Save the following lines as [Link], with the use of any text editor such as vim on Linux
or Notepad on Windows.

When we execute above program on a Windows machine, it will produce following


result:

6.30.3 Python Interpreter - Using Shebang #!


In addition to executing the Python script as above, the script itself can be a
selfexecutable in Linux, like a shell script. You have to add a shebang line on top of the
script. The shebang indicates which executable is used to interpret Python statements in
the script. Very first line of the script starts with #! And followed by the path to Python
executable.

Modify the [Link] script as follows –

To mark the script as self-executable, use the chmod command

217
You can now execute the script directly, without using it as a command-line argument.

6.31 Python – Syntax

The Python syntax defines a set of rules that are used to create a Python Program. The
Python Programming Language Syntax has many similarities to Perl, C, and Java Programming
Languages. However, there are some definite differences between the languages.
First Python Program
Let us execute a Python program to print "Hello, World!" in two different modes of Python
Programming. (a) Interactive Mode Programming (b) Script Mode Programming.
Python - Interactive Mode Programming
We can invoke a Python interpreter from command line by typing python at the command
prompt as following –

Here >>> denotes a Python Command Prompt where you can type your commands. Let's type
the following text at the Python prompt and press the Enter –

If you are running older version of Python, like Python 2.4.x, then you would need to use
print statement without parenthesis as in print "Hello, World!". However, in Python version
3.x, this produces the following result −

Python - Script Mode Programming


We can invoke the Python interpreter with a script parameter which begins the execution
of the script and continues until the script is finished. When the script is finished, the interpreter
is no longer active.
Let us write a simple Python program in a script which is simple text file. Python files have
extension .py. Type the following source code in a [Link] file −

218
assume that you have Python interpreter path set in PATH variable. Now, let's try to run this
program as follows −

This produces the following result −

6.32 Python Reserved Words

The following list shows the Python keywords. These are reserved words and you cannot
use them as constant or variable or any other identifier names. All the Python keywords contain
lowercase letters only.

6.33 Python Lines and Indentation

Python programming provides no braces to indicate blocks of code for class and
function definitions or flow control. Blocks of code are denoted by line indentation, which is
rigidly enforced.

The number of spaces in the indentation is variable, but all statements within the block must be
indented the same amount. For example −

219
6.34 Python – Variables
Python variables are the reserved memory locations used to store values with in a Python
Program. This means that when you create a variable you reserve some space in the memory.
Based on the data type of a variable, Python interpreter allocates memory and decides what can
be stored in the reserved memory. Therefore, by assigning different data types to Python
variables, you can store integers, decimals or characters in these variables.
6.34.1 Creating Python Variables

Python variables do not need explicit declaration to reserve memory space or you
can say to create a variable. A Python variable is created automatically when you assign
a value to it. The equal sign (=) is used to assign values to variables.

The operand to the left of the = operator is the name of the variable and the operand
to the right of the = operator is the value stored in the variable. For example –

Example to Create Python Variables This example creates different types (an
integer, a float, and a string) of variables.

6.34.2 Printing Python Variables


Once we create a Python variable and assign a value to it, we can print it
using print() function. Following is the extension of previous example and shows how to
print different variables in Python:

Example to Print Python Variables


This example prints variables.

220
6.34.3. Deleting Python Variables

can delete the reference to a number object by using the del statement. The
syntax of the del statement is −

6.35. Python Data Types

Python data types are actually classes, and the defined variables are their instances or
objects. Since Python is dynamically typed, the data type of a variable is determined at runtime
based on the assigned value.
In general, the data types are used to define the type of a variable. It represents the type of data
we are going to store in a variable and determines what operations can be done on it.
Each programming language has its own classification of data items. With these datatypes, we
can store different types of data values.
Types of Data Types in Python
Python supports the following built-in data types −

6.36. Python – Operators

Python operators are special symbols used to perform specific operations on one or more
operands. The variables, values, or expressions can be used as operands. For example, Python's

221
addition operator (+) is used to perform addition operations on two variables, values, or
expressions.

The following are some of the terms related to Python operators:

6.36.1. Types of Python Operators

Python operators are categorized in the following categories −

6.36.2 Python Arithmetic Operators


Python Arithmetic operators are used to perform basic mathematical operations
such as addition, subtraction, multiplication, etc.

The following table contains all arithmetic operators with their symbols, names,
and examples (assume that the values of a and b are 10 and 20, respectively) −

222
6.36.3. Python Comparison Operators

Python Comparison operators compare the values on either side of them and
decide the relation among them. They are also called Relational operators.

The following table contains all comparison operators with their symbols,
names, and examples (assume that the values of a and b are 10 and 20, respectively) –

223

You might also like