•0 gostou•29 visualizações

Denunciar

Compartilhar

Baixar para ler offline

Introduction to python programming this will help you to increase your python basics and make your future python learning easy.

- 1. Dr. Jeetashree Aparajeeta Assistant Professor (Sr) SENSE
- 2. Introduction to Problem Solving ◦ Problem Solving: Definition and Steps ◦ Problem Analysis Chart ◦ Developing an Algorithm ◦ Flowchart ◦ Pseudocode 2
- 3. Use of computer technology help in completing any task in a much faster and accurate manner. Ex. Paying electric bill, booking a health check up, ordering your favorite food, booking movie tickets etc. These technologies follow a proper problem solving approach for an essential skill to solve the related problems. Ex. You cannot order food using Apollo247 App. 3
- 4. The standard computers, that we use, are not advance enough to solve a problem of their own, so we need to feed step-by-step instructions to the computer to solve any problem. The efficiency in solving the problem depends upon how correctly and precisely we define the problem, design a solution (algorithm) and implement the solution (program) using a programming language. 4
- 5. So, the problem solving can be defined as the process of identifying a problem, developing an algorithm for the identified problem and finally implementing the algorithm to develop a computer program. 5
- 6. The correctness of the output that a computer gives depends upon the correctness of input provided. Key steps required for solving a problem I. Analyzing the problem II. Developing an algorithm a. Flowchart b. Pseudocode III. Coding IV. Testing and Debugging 6
- 8. Analysing the problem It is important to clearly understand a problem before we begin to find the solution for it. If we are not clear as to what is to be solved, we may end up developing a program which may not solve our purpose. Thus, we need to read and analyse the problem statement carefully in order to list the principal components of the problem and decide the core functionalities that our solution should have. By analysing a problem, we would be able to figure out what are the inputs that our program should accept and the outputs that it should produce
- 9. 4.2.1 Analysing the problem It is important to clearly understand a problem before we begin to find the solution for it. If we are not clear as to what is to be solved, we may end up developing a program which may not solve our purpose. Thus, we need to read and analyse the problem statement carefully in order to list the principal components of the problem and decide the core functionalities that our solution should have. By analysing a problem, we would be able to figure out what are the inputs that our program should accept and the outputs that it should produce.
- 10. 4.2.2 Developing an Algorithm It is essential to device a solution before writing a program code for a given problem. The solution is represented in natural language and is called an algorithm. We can imagine an algorithm like a very well-written recipe for dish. We start with a tentative solution plan and keep on refining the algorithm until the algorithm is able to capture all the aspects of the desired solution. For a given problem, more than one algorithm is possible and we have to select the most suitable solution
- 11. 4.2.3 Coding After finalising the algorithm, we need to convert the algorithm into the format which can be understood by the computer to generate the desired solution. Different high level programming languages can be used for writing a program
- 12. 4.2.4 Testing and Debugging The program created should be tested on various parameters. The program should meet the requirements of the user. It must respond within the expected time. It should generate correct output for all possible inputs. In the presence of syntactical errors, no output will be obtained. In case the output generated is incorrect, then the program should be checked for logical errors, if any.
- 33. 33 Separate the problem into three components Input A list of data source Provided to the problem Output A list of the output required Processing A list of actions needed to produce the required outputs.
- 34. PAC is used to analyze a problem. It has four sections: a. The given data b. The required result c. The processing involved d. A list of solution alternative 34
- 35. Given Data Required result Section 1 Data given in the problem/ provided by the user Section 2 Requirements for the output reports including the information needed and the format required Processing Required Solution Alternative Section 3 List of processing required including equations or other types of processing. Section 4 List of ideas for the solution of the problem 35
- 36. Problem: A program is required to find average of five numbers. 36
- 37. 37 Given Data Required result Number 1 Number 2 Number 3 Number 4 Number 5 Average of 5 numbers Processing Required Solution Alternative Total = Number 1 + Number 2 + Number 3 + Number 4 + Number 5 Average = Total / 5 i. Define the numbers as constants ii. Define the numbers as input values
- 38. Total = 5 + 6 + 8 + 9 + 11 Or Number 1 = 5, Number 2 = 6, Number 3 = 8, Number 4 = 9, Number 5 = 11 Or Number = “Ask the user to provide the number” 38
- 39. Calculate the gross pay of an employee. The formula to be used : GrossPay = Hours x Payrate 39
- 40. 40 Given Data Required result Hours PayRate Gross Pay Processing Required Solution Alternative GrossPay = Hours * PayRate 1. Define the hours worked and Payrate as constant 2. Define the hours worked and PayRate as input
- 41. Convert the distance in KM to miles where 1 mile = 1.609 km 41
- 42. 42 Given Data Required result Distance in km Distance in mile Processing Required Solution Alternative Mile = km/1.609 1. Define the km as constant 2. Define the km as input
- 43. An algorithm is an effective method expressed as a finite list of well defined instructions for calculating a function, starting from an initial state and initial input. The instructions describe a computation, which will eventually produce output, when executed. Algorithm can be used to solve any kind of problems. However, before writing a program, we need to write the steps to solve the problem in simple English language. This step-by-step procedure to solve the problem is called algorithm. 43
- 44. The way of execution of program is categorized as ◦ Sequence Statements ◦ Selection Statements ◦ Iteration or Looping Statements (Called Control Structure) 44
- 45. In this program, all the instructions are executed one after another. Ex: Algorithm to find the area of a rectangle ◦ Step 1: Start ◦ Step 2: Take length and breadth and store them as L and B ◦ Step 3: Multiply by L and B and store it in Area ◦ Step 4: Print Area ◦ Step 5: Stop 45
- 46. In this type of programming, some portion of the program is executed based upon the conditional test. If the conditional test is true, compiler will execute some part of the program, otherwise it will execute the other part of the program. 46
- 47. Ex: Algorithm to check whether a candidate is eligible to vote? ◦ Step 1: Start ◦ Step 2: Take age and store it in Age ◦ Step 3: Check Age value, if age > 18, then go to step-4 else Step-5 ◦ Step 4: Print “Eligible to Vote” and go to Step-6 ◦ Step 5: Print “Not Eligible to Vote” ◦ Step 6: Stop 47
- 48. Two common methods are used to represent an algorithm a. Flowchart b. Pseudocode Either of the methods can be used to represent an algorithm. 48
- 49. The flowchart and pseudocode showcases the logic of the solution required to solve the problem excluding any implementation details. We can understand the flow of control during execution of the program. 49
- 50. Visual representation of an algorithm It is a diagram made up of boxes, diamonds and other shapes, connected by arrows. Each shape represents a step of the solution process and the arrow represents the order or link among the steps. 50
- 51. A flow chart is an organized combination of shapes, lines and text that graphically illustrate a process or structure. 51
- 52. Write an algorithm to find the square of a number 52
- 53. Before developing the algorithm, first identify the input, process and output. ◦ Input: Number whose square is required ◦ Process: Multiply the number by itself to get its square ◦ Output: Square of the number 53
- 54. Step 1: Input a number and stored it to Number (Number is a variable) Step 2: Compute Number * Number and store it in Square (Square is a variable) Step 3: Print Square 54
- 55. 55
- 56. 56
- 57. Pseudocode is another way of representing an algorithm. It is a kind of structured English for describing algorithms It allows the designer to focus on the logic of the algorithm without being distracted by details of language syntax Pseudocode needs to be complete It describe the entire logic of the algorithm so that implementation becomes a rote mechanical task of translating line by line into source code 57
- 58. Each instruction is written on a separate line Keywords and indentation are used to signify particular control structures Each set of instructions is written from top to bottom, with only one entry and one exit Groups of statements may be formed into modules, and that group given a name. 58
- 59. Several keywords are often used to indicate common input, output, and processing operations Input: READ, OBTAIN, GET Output: PRINT, DISPLAY, SHOW Compute: COMPUTE, CALCULATE, DETERMINE Initialize: SET, INIT Add one: INCREMENT, BUMP, DECREMENT 59
- 60. Area of Rectangle. 60
- 61. READ height of Rectangle READ width of Rectangle COMPUTE area as height times width PRINT area of rectangle 61
- 63. Format IF Condition THEN Statements ELSE Statement ENDIF Example IF Hours_Worked > Normal_Max THEN Display overtime message ELSE Display regular time message ENDIF 63
- 64. Format WHILE Condition Statements ENDWHILE Example WHILE Population < Limit Compute Population as Population + Births ‐ Deaths ENDWHILE 64
- 65. Format FOR Iteration Bounds Statements ENDFOR Example FOR each student in the list Print Register_Number ENDFOR 65
- 67. 67

- Flow Charts are used to help programmers during the early stages ofprogramming.Flow Charts allow the programmer to set out, in a very simple way thesequence that he/she wants for each line of the program.A flow chart is an organized combination of shapes, lines and text thatgraphically illustrates a process or structure.Here's an example of how you could use shapes, lines, and text to build achart:• The shapes (such as rectangles, circles, or diamonds) represent each stepor decision point in the process.• The lines show the continuity of the process, demonstrating the paths theuser should follow.• The text briefly describes each part of the process.A flow chart can be used for:(1) defining and analyzing processes(2) building a step-by-step picture of the process for analysis, discussion, orcommunication purposes(3) defining, standardizing, or finding areas for improvement in a process