Tuesday 14 February 2017

Python Programming Unit-1

I. COMPUTER FUNDAMENTALS: CHARACTERISTICS OF COMPUTER 1. High speed: Computers have the ability to perform routine tasks at a greater speed than human beings. They can perform millions of calculations in seconds.
 2. Accuracy: The computer accepts large amount of data and performs specified calculations and produces accurate results. Some people comment that computers also make mistakes. But it is not. It is the mistake on the part of human beings. The mistake might have happened because of wrong input or wrong program given by the human beings.

 3. Storage: Computers can store large amount of information. Any item of data or any instruction stored in the memory can be retrieved by the computer at lightning speeds
.
 4. Automation: Computers are capable of executing the programs without the need of human intervention, the computer execute programs one by one automatically.

 5. Diligence: Computers can perform the same task repeatedly & with the same accuracy without getting tired. A computer will work with same tempo from beginning to end.

 6. Cost effectiveness: Computers reduce the amount of paper work and human effort, thereby reducing costs.


REGISTER: Register is used to quickly accept, store, and transfer data and instructions that are being used immediately by the CPU. There are various types of Registers those are used for various purposes. • AC Or Accumulator, • Data Register Or DR, • AR Or Address Register, • Program Counter (PC), • Memory Data Register (MDR) , • Index Register, • Memory Buffer Register.

 Accumulator: 
This register is used for storing results those are produced by the system. When CPU will generate some results after the processing then all the results will be stored in to AC Register.
Data Register: This register is used in micro computers to temporarily store data being transmitted to or from peripheral device.
Address Register: This register holds the memory address of data and instructions. This is used for access data and instructions from memory during execution phase of an instructions.
 Program Counter: It is commonly called the instruction pointer in inter X86 microprocessor. It keeps track of the next memory address of the instruction that is to be executed once the execution of current instruction is completed.
Memory Data Register: MDR is the register of a computer’s control unit that contains the data to be stored in computer storage (RAM).It acts like a buffer and holds anything that is copied from the memory ready for the processor to use it.
 Index Register: (Base Register) A hardware element which holds a number that can be added to the address portion of computer instruction to form an effective address.
Memory Buffer Register: This is register holds the contents of data and instructions read from memory or written in memory.
 II. PLANNING THE COMPUTER PROGRAM:

 PROBLEM SOLVING

Solving problems is the core of computer science. Programmers must first understand how a human solves a problem, then understand how to translate this "algorithm" into something a computer can do, and finally how to "write" the specific syntax (required by a computer) to get the job done. It is sometimes the case that a machine will solve a problem in a completely different way than a human. Computer Programmers are problem solvers. In order to solve a problem on a computer you must: 1. Know how to represent the information (data) describing the problem. 2. Determine the steps to transform the information from one representation into another.

 PROBLEM DEFINITION: Design a program that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas
. Program design:
Program design is both a verb and a noun. It is the process that organizations use to develop a program. Ideally, the process is collaborat ive, iterative, and tentative—stakeholders work together to repeat, review, and refine a program until they believe it will consistently achieve its purpose. A program design is also the plan of action that results from that process. Ideally, the plan is developed to the point that others can implement the program in the same way and consistently achieve its purpose.

 DEBUGGING: In computers, debugging is the process of locating and fixing or bypassing bugs (errors) in computer program code .To debug a program or hardware device is to start with a problem, isolate the source of the problem, and then fix it. A user of a program that does not know how to fix the problem may learn enough about the problem to be able to avoid it until it is permanently fixed. Debugging is a necessary process in almost any new software or hardware development process, whether a commercial product or an enterprise or personal application program

TYPES OF ERROS: Types of program errors We distinguish between the following types of errors:
 1. Syntax errors: errors due to the fact that the syntax of the language is not respected.
 2. Semantic errors: errors due to an improper use of program statements
 3. Logical errors: errors due to the fact that the specification is not respected. From the point of view of when errors are detected, we distinguish:
 1. Compile time errors: syntax errors and static semantic errors indicated by the compiler
2. Runtime errors: dynamic semantic errors, and logical errors, that cannot be detected by the compiler (debugging).
 DOCUMENTATION: In computer hardware and software product development, documentation is the information that describes the product to its users. It consists of the product technical manuals and online information. The term is also sometimes used to mean the source information about the product contained in design documents, detailed code comments, white papers, and blackboard session notes.
 Comments: There are two types of comments statements. They are
 1. Single line comment
 2. Multi line comment
 Single line comment: In Python, we use the hash (#) symbol to start writing a comment. It extends up to the New line character. Ex: # this is single line comment
 Multiline comment: Another way of doing this is to use triple quotes, either ''' or """. These triple quotes are generally used for multi-line strings. Ex: ‘’’ this is multi line comments We are learning python…. Thank you….’’’

 III. TECHNIQUES OF PROBLEM SOLVING:

 ALGORITHM
 1. A sequential (step by step) solution of any program that written in human language, called algorithm.
2. Algorithm is first step of the solution process, after the analysis of problem, programmer writes the algorithm of that problem.
 Q. Write algorithm and flowchart to input temperature, if temperature is less than 32 then print "below freezing" otherwise print "above freezing"?

ALGORITHM: step 1 : start
step 2 : input number is temp



step 3 : if (temp<32)
                        {
                          Printf(“below freezing”);
                        Else
                          Printf(“above freezing”);
                        }
step 5 : stop

FLOW CHART

 Flow chart is a graphical or symbolic representation of a process. Each step in the process is represented by a different symbol and contains a short description of the process step. The flow chart symbols are linked together with arrows showing the process flow direction.
Common Flowchart Symbols
Different flow chart symbols have different meanings. The most common flow chart symbols are:
·         Terminator: An oval flow chart shape indicating the start or end of the process.
·         Process: A rectangular flow chart shape indicating a normal process flow step.
·         Decision: A diamond flow chart shape indication a branch in the process flow.
·         Connector: A small, labeled, circular flow chart shape used to indicate a jump in the process flow. (Shown as the circle with the letter “A”, below.)
·         Data: A parallelogram that indicates data input or output (I/O) for a process.




Decision tables are compact (beautifully) and precise (frankly) ways of modeling complicated logic, such as that which you might use in a computer program. They do this by mapping the different states of a program to an action that a program should perform. Decision tables take on the following format:
The four quadrants
Conditions stub
Condition entries
Actions stub
Action entries
The limited-entry decision table is the simplest to describe. The condition alternatives are simple Boolean values, and the action entries are check-marks, representing which of the actions in a given column are to be performed.
Example: Decision Tables
A  computer game example, for a football simulation the following rules are set up.
Rules
Conditions
90 minutes
Y
Y
Y
Team A Winning
Y
Team B Winning
Y
Y
Draw
Y
Actions
Game Over
X
X
Team A Wins
X
Team B Wins
X
Extra Time
X
Keep Playing
X
X
What happens when:
1.    90 minutes up
2.    the game is a draw
Answer: Keep Playing and give them some extra time





STRUCTURED PROGRAMMING CONCEPTS:


Procedural Programming Languages: These languages code programs in such a way that the program executes statement by statement, reading and modifying a shared memory.
Examples: Pascal, FORTRAN, COBOL
The structured programming concept was formalized in the year 1966 by Corrado Böhm and Giuseppe Jacopini.
Structured programming (sometimes known as modular programming) is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify.
Structured programming is not only limited to the top down approach. It employs methods using:-
1.   Top down analysis for problem solving: It focuses on dividing the problem into sub parts and hence simplifies the problem solving.
2.   Modularization for program structure and organization: It organizes large instructions by breaking them into separate and smaller section of modules, sub routines and subprograms.
3.   Structured code for the individual modules: Control structures are used to determine the exact order in which the set of instructions are to be executed. Therefore, a structured code does not involve GOTO statement as it represents no certain order of execution.
Example ALGOL, Pascal, Pl/I, C , Ada