Professional Documents
Culture Documents
For More Subjects
For More Subjects
https://www.studymedia.in/fe/notes
Programming and Problem
Solving [110005]
Examples:
what career?
what course?
What shoes?
4. List instructions that enable you to solve the problem using selected
solution
5. Select the best way to solve the problem from the list of alternative
solutions
10/11/2022
Heuristic
10/11/2022
Algorithmic solution:
Heuristic solutions:
10/11/2022
Design
Maintenance 13
Other Subjects: https://www.studymedia.in/fe/notes
Algorithm
Writing Algorithms
After using the Interactivity chart and the IPO(Input-Process-Output) chart the next
step in organising the solution is to for the programmer to develop a set of
instructions for the computer – called algorithms.
Algorithm:
Def: It is defined as a finite set of instructions that describe a method for solving a
problem. In other words it is a step by step procedure for solving a problem.
Sorting
Searching
Let us write down the algorithm for a problem that is familiar to us.
3. number mod by 10
5. number divide by 10
8. Stop
10/11/2022
10/11/2022
a. accurate
a. Unambiguous
b. Executable
are used to indicate the steps & decisions that are taken as the process moves
Individual steps are represented by boxes and other shapes on the flowchart,
with arrows between those shapes indicating the order in which the steps are
taken.
10/11/2022
Process
Input or output
Decision
Flow line
Connector
Off-page connector
10/11/2022
Other Subjects: https://www.studymedia.in/fe/notes
PSEUDO CODE
operations
10/11/2022
Read Print
Read student name Print ‘Program Complete’
Write
10/11/2022
Add Initialise
Add num1 to num2 Initialise totalPrice to zero
Subtract Set
Subtract num1 from num2 Set totalPrice to zero
Multiply Store
Multiply num1 by num2 Store zero in totalPrice
Divide
Divide num1 by num2
10/11/2022
IF…THEN…ELSE DOWHILE
10/11/2022
10/11/2022
Example 1: Example 2:
Print 1 to n numbers Addition of two numbers:
BEGIN BEGIN
GET n GET a,b
INITIALIZE i=1 ADD c=a+b
FOR (i<=n) DO PRINT c
PRINT i END
i=i+1
ENDFOR
END
10/11/2022
1
Other Subjects: https://www.studymedia.in/fe/notes
TOP-DOWN DESIGN
Top-Down Design
Problem-solving technique in which the problem is divided into
Subproblems; the process is applied to each subproblem.
Modules
Self-contained collection of steps, that solve a problem or subproblem.
Abstract Step
An algorithmic step containing unspecified details.
Concrete Step
An algorithm step in which all details are specified
2
Other Subjects: https://www.studymedia.in/fe/notes
A General Example
Planning a large party
3
Other Subjects: https://www.studymedia.in/fe/notes
Subdividing the party planning
HISTORY OF PYTHON
• Python was developed by Guido van Rossum
• Python is derived from many other languages, including ABC, Modula-3, C, C++,
Algol-68, Smalltalk, and Unix shell and other scripting languages.
4
Other Subjects: https://www.studymedia.in/fe/notes
PROGRAMMING BASICS
• code or source code: The sequence of instructions in a program.
• syntax: The set of legal structures and commands that can be used in a
particular programming language.
• Compiler-is a program which takes a high level programming language and
translates that language to a machine level programming language.
• Interpreter-An interpreter is a program which you interact with, and y ou feed the
instructions in your language, in this case python.
• output: The messages printed to the user by a program.
• console: The text box onto which output is printed.
– Some source code editors pop up the console as an
external window, and others contain their own console window.
5
Other Subjects: https://www.studymedia.in/fe/notes
6
Other Subjects: https://www.studymedia.in/fe/notes
FEATURES OF PYTHON
Simple
7
Other Subjects: https://www.studymedia.in/fe/notes
FEATURES OF PYTHON
High-level Language
When you write programs in Python, you never need to bother about the low-
level details such as managing the memory used by your program, etc.
Portable
Due to its open-source nature, Python has been ported to (i.e. changed to make
it work on) many platforms. All your Python programs can work on any of
these platforms without requiring any changes at all if you are careful enough to
avoid any system-dependent features.
8
Other Subjects: https://www.studymedia.in/fe/notes
FEATURES OF PYTHON
Interpreted
Python, on the other hand, does not need compilation to binary. You just
run the program directly from the source code.
Internally, Python converts the source code into an intermediate form called
byte codes and then translates this into the MACHINE language of your
computer and then runs it.
All this, actually, makes using Python much easier since you don't have to
worry about compiling the program, making sure that the proper libraries are
linked and loaded, etc.
This also makes your Python programs much more portable, since you can
just copy your Python program onto another computer and it just works!
9
Other Subjects: https://www.studymedia.in/fe/notes
FEATURES OF PYTHON
Object Oriented
Python supports procedure-oriented programming as well as object-oriented
programming.
In procedure-oriented languages, the program is built around procedures or
functions which are nothing but reusable pieces of programs.
In object-oriented languages, the program is built around objects which combine
data and functionality.
Extensible
If you need a critical piece of code to run very fast or want to have some piece
of algorithm not to be open, you can code that part of your program in C or C++
and then use it from your Python program.
10
Other Subjects: https://www.studymedia.in/fe/notes
FEATURES OF PYTHON
Embeddable
You can embed Python within your C/C++ programs to give scripting capabilities for y
program's users.
Extensive Libraries
The Python Standard Library is huge indeed. It can help you do various things
involving regular expressions, documentation generation, unit testing, threading,
databases, web browsers, CGI, FTP, email, XML, XML-RPC(Extensible Markup
Language remote procedure call)), HTML, WAV files, cryptography, GUI (graphical user
interfaces), and other system-dependent stuff. Remember, all this is always available
wherever Python is installed. This is called the Batteries Included philosophy of Python.
So there is huge scope for python in the future ahead.
You can rely on it for a better career as a programmer/software developer. 11
Other Subjects: https://www.studymedia.in/fe/notes
INSTALLATION OF PYTHON ON WINDOWS
we are selecting the version 3.7 of python
for installation .
First go to the authentic web site of
Python https://www.python.org
Click on Downloads then Search for
Python 3.7 for windows
Scroll down and see the table of files.
From this click on the Windows x86-64
executable installer file
An .exe file will be get downloaded
Run that file on your PC or Laptop by
double clicking on that
2
4
16
Other Subjects: https://www.studymedia.in/fe/notes
MODES OF WORKING IN PYTHON
18
Other Subjects: https://www.studymedia.in/fe/notes
MULTIPLE ASSIGNMENT
19
Other Subjects: https://www.studymedia.in/fe/notes
Variable Names
A variable can have a short name (like x and y) or
a more descriptive name (age, carname, total_volume).
Multiple
words can be separated using an
underscore, like this_is_a_long_variable
22
Other Subjects: https://www.studymedia.in/fe/notes
Literals in Python
Literals is a raw data given in a variable or Boolean literal- It has two values True and False
consatnts Special literal-Special literal in python is None
1.Numeric
2.String
3.List
4.Tuple
5.Directory
Python Tuple : Tuple is an ordered sequence of items same as list. The only difference is
that tuples are immutable. Tuples once created cannot be modified
e. g. tuple = (1,2,’Red’, ‘green’)
Python Strings : String is collection of characters . To define the string we can use
single, double, triple quote. Two operators like + and * can used with string.
Ex- Str1= ‘I love programming.’
Input Operation :
In Python the input() function is used to take input from the user.
It prompts for the user input and reads a line. After reading data, it converts it into a string and returns that. It
throws an error EOF Error if EOF is read.
Program to check input
# type in Python
A hash sign (#) that is not inside a string literal begins a comment. All characters
after the # and up to the end of the physical line are part of the comment and the
Python interpreter ignores them.
Live Demo
#!/usr/bin/python
# First comment
Python 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 –
# Addition of numbers
Operator Name Example
add = a + b
+ Addition x+y
# Subtraction of numbers
- Subtraction x-y sub = a - b
* Multiplication x*y
# Multiplication of number
/ Division x/y mul = a * b
% Modulus x%y
# Division(float) of number
** Exponentiation x ** y div1 = a / b
// Floor division x // y
# Division(floor) of number
div2 = a // b
# Power
p = a ** b
Other Subjects: https://www.studymedia.in/fe/notes
Comparison Operator
Comparison operators are used to comparing the value of the two operands and returns Boolean true
or false accordingly.
# Examples of Relational
Operators
a = 13
b = 33
Opera Name Example
tor # a > b is False
print(a > b)
== Equal x == y
!= Not equal x != y
# a < b is True
> Greater than x>y print(a < b)
+= x += 3 x=x+3
# Assign value
-= x -= 3 x=x-3
b = a
*= x *= 3 x=x*3 print(b)
/= x /= 3 x=x/3
%= x %= 3 x=x%3 # Add and assign value
b += a
//= x //= 3 x = x // 3 print(b)
**= x **= 3 x = x ** 3
&= x &= 3 x=x&3 # Subtract and assign value
b -= a
|= x |= 3 x=x|3
print(b)
^= x ^= 3 x=x^3
>>= x >>= 3 x = x >> 3 # multiply and assign
<<= x <<= 3 x = x << 3 b *= a
Other Subjects: https://www.studymedia.in/fe/notes
print(b)
LOGICAL OPERATORS
not Logical Used to reverse the logical state of its Not(a and
# Print not a is False
NOT operand. b) is false. print(not a)
b = 0000 1101
# Print bitwise NOT operation
----------------- print(~a)
if (y in list):
Evaluates to true if it does not print("y is present in given
x not in y, here not in results in a 1
not in finds a variable in the specified list")
if x is not a member of sequence y. else:
sequence and false otherwise.
print("y is NOT present in
given list")
Other Subjects: https://www.studymedia.in/fe/notes
IDENTITY OPERATORS
P-parenthesis
Prefix
Ex.- ++Y E-exponents