Python Tutorial
Python Tutorial
6.To acquaint with the use and benefits of files handling in Python
Course Outcomes:
On completion of the course, learner will be able to–
Co1: inculcate and apply various skills in problem solving.
CO2: Choose most appropriate programming constructs and
features to solve the problems in diversified domains.
CO3: Exhibit the programming skills for the problems those require
the writing of well documented programs including use of the logical
constructs of language, Python.
CO4: Demonstrate significant experience with the Python program
development environment
Unit I Problem Solving , Programming and Python
Programming
What is Problem ?
1. A Problem is a state of difficulty that need to be resolved
2. While solving a problem there is a desire to attain some specific
goal .
Here is some examples we face in day to day life can be important or
can be least importance .
1. Will I get proper transport to go to my workspace ?
2. Should I wear shoes today ?
3. Should I go to a movies ?
4. Which Mobile phone should I buy?
General Problem Solving Concepts : Six steps of Problem Solving
1. Define the Problem
4. Select a Solution
For solving some problem , series of actions are taken to reach the solution.
With heuristic solution problem solver has to follow six steps of problem solving for more
than once .
Problem solving with computer
Solution : In is the instruction that must be followed to produce the beat
result .
The field of computer that deal with solving the heuristic problems is
called artificial intelligence .
Difficulties with problem solving
For a complex problem, its algorithm is often divided into smaller units called
modules .
1. Top-Down Approach
2. Bottom- up approach
Control structure used in Algorithm
An algorithm has a finite number of steps and some steps may involve decision
making and repetition .
Broadly speaking an algorithm may employ three control structures, namely
Sequence , Decision , Repetition.
Sequence : Sequence means that each step of algorithm is executed in the
specific order.
Decision : Decision statement are used when the outcome of the process
depends on some condition .
Repetition : Which involves executing one or more steps for a number of times
.
Examples of Algorithm
1. Write an algorithm for swapping two number
2. Write an algorithm to find the larger of two number
3. Write a algorithm that number is even or odd
Flowchart
A flowchart is a graphical or symbolic representation of a process .
Flowchart is pictorial view of algorithm
When designing a flowchart , each step in the process is depicted by
different symbol and is associate with short symbol .
Flowchart Symbol
Examples of Flowchart
1. Draw a flowchart to calculate the sum of first 10 natural number
2. Draw a flowchart to add two number
3. Draw a flowchart to calculate the salary of a daily wager
4. Draw a flowchart to determine the largest of three numbers
Pseudocodes
Pseudocodes is a compact and informal high level description of an
algorithm that uses the structural conventional of a programming
languages.
Pseudocode must be complete , describing the entire logic of the
algorithm , so that can be translated strainghway into a programming
languages.
Pseudocode are an outline of a program that can easily be converted into
programing statements .
Pseudo Codes examples
1. Write a psudocode for calculating the price of product after adding the
sales tax to its original price .
Part C: Basics of Python Programming
Monty Python’s
Flying circus ( a
BBC Comedy
series from the
70’s)
Version details
1. Version 1.0 was released in 1991.
Interview: Guido van Rossum - The Modern
2. Version 2.0 was released in 2000 . Era of Python
3. Python 2.7 last release of 2.0 version. Coursera Interview Link of Guido Van
Rossum : Click
4. Python 3.0 was relased in 2008. Interview Reference :
https://www.coursera.org/
5. Current version is 3.6.4.
Application of Python
print(576)
print(5.6)
print(“Hello World”)
big part of any programming language is the syntax for constants. So, like a 576 or 5.6, numbers both
integer and floating point numbers. We've been using this on calculators. They make a lot of sense to us.
The kind of constants that are a little bit different are things like string constants. So "Hello world" is a
string constant. We use that so that our program can say nice things to people that are using our program.
And so, we call them constants because they don't change but it's kind of obvious, constants.
Variable and Identifiers
Using just constants you cannot do much in your program .For developing
little complex program , you need to store information and manipulate it as
required .THis is where variables can help.
Variables are reserved memory locations that stores values.
Identifiers are names given to something .
This somethings can be a variable , function, class , modules or objects.
Choice variable name sensible.
Python Variable Name Rules
Must start with letter or (_) underscore .
Case sensitive
x1q3z9ocd=35.0 hours=35.0
rate=12.50
x1q3z9afd=12.50 pay=hours*rate
print(pay)
x1q3p9afd=x1q3z9ocd*x1q3z9afd