Assignment related to Algorithm-flowchart-Python

User Generated

wnvpx

Computer Science

Description

See guideline on the file

Unformatted Attachment Preview

Python Lesson We have previously discussed the 3 major programming constructs: 1‐ Sequence 2‐ Selection 3‐ Iteration These constructs help us to write algorithms that can then be translated into code. Programming has been known to be a difficult thing to learn to do. You could say, there is a steep learning curve. I think, this is primarily due to the fact that most people have not had exposure to programming before their first programming course. I would say, you are learning a new way to solve problems AND learning how to express those solutions in a language you do not know and are learning, at the same time. Not to mention, the language is not interpreted by a human who can interpolate what you mean. The language is interpreted by a machine, more specifically, a compiler or interpreter. A compiler requires precision and can only understand what it has been taught to understand. So, you have to learn to speak the compiler’s language, so to speak. I tell my students, learning to program for the first time is like being sent to a country, where you do not speak the language, to teach someone how to build a house, and you have no clue how to build a house or how to use the tools you need, and you have to teach someone to build the house in a language you do not know. Since programming can be so challenging, it is often helpful to be able to view an algorithm in many different ways. This helps to build mental models, so you can “visualize” the code and how it runs. Today, we will look at 3 ways to “visualize” a solution to a problem that will eventually be transformed into a computer program: Solution Overview, Flow Chart, Code Solution Overview: One way to visualize the code is through a written algorithm. We can think of these as steps to be followed written in human language. Remember, an algorithm is a step by step set of instructions to solve a specific task. Let’s look at a problem together. Let’s say we have a list of numbers and we have been tasked to write a program to ask the user for 10 numbers, then our computer program will determine the smallest number in the list. There are few steps before we have an executable program. 1. Analyze the problem 2. Write a solution (algorithm) in English words 3. Draw a flow chart of the solution 4. Write the solution in the Python Programming Language 5. Run the Python program through a Python Interpreter to execute the program. 1. Analyze the problem What information is coming in? Input: 10 numbers What information is going out? Output: 1 number, the small number of the 10 numbers How are we going to do this? Processing: Let’s think about how a person would do this. Let’s assume, I have told Jack to listen to the numbers I call out and remember only the smallest number and tell me that number when I finish. Does Jack have to remember all of the numbers? No, he only has to know the number I just said (current) and the most recent minimum number (minimum). So, here is what Jack does: Listens for the first number, which automatically becomes the minimum, since it is the only number so far. Then he listens for the next number, he checks to see if the new number is less than the minimum. If it is less than the minimum, he has a new minimum. If it isn’t, he does not have to do anything. Then Jack again, listens for the next number. Now, I’m going to rewrite the last paragraph and Bold the sequence statements, italicize the selection statements, and underline the repeating words. Listens for the first number, which automatically becomes the minimum, since it is the only number so far. Then he listens for the next number, he checks to see if the new number is less than the minimum. If it is less than the minimum, he has a new minimum. If it isn’t, he does not have to do anything. Then Jack again, listens for the next number. 2. Write a solution overview (algorithm) in English words The above paragraph is helpful, but we have to move it toward a form that is more computer programmable. Step 1: Set a variable called counter to 1 in order to help us count how many times we get a number Step 2: While counter < 10, continue to Step 3, otherwise, go to Step 7 Step 3: Get the first number store into a variable called min Step 4: Get the next number store into a variable called cur Step 5: If cur < min then, store min into cur (cur = min) Step 6: increment counter by 1 Step 7: Stop 3. Draw a flowchart of the solution The following symbols will be required to create a flow chart: Ovals are indicators for start and stop Rectangles are used for basic sequence statements Parallelograms are used for input and output statements Diamonds are used for decisions (selection and iteration) Let’s look at the flow chart for the solution overview above: 4. Write the solution in the Python Programming Language Now, let’s learn what is needed to write this in Python. Assignment: To set counter to 1, we do something like: counter = 1 Input: To get a number (in Integer form) from the user, we do something like: min = int(input(“Please enter an integer”)) Output: To output the solution: print(min) If: To perform selection: if (cur < min): Loop: To do iteration: while (counter < 10): Let’s put it all together: counter = 1 min = int(input("Enter an integer")) while (counter < 10): cur = int (input("enter an integer")) if (cur < min): min = cur counter = counter + 1 print("Min is ", min); print("DONE") 5. Run the Python program through a Python Interpreter to execute the program. To run this, there are a couple of options: 1. Download the Python IDLE Environment and Interpreter. You can find this at python.org. 2. Go to codepad.org and choose Python and type the program in and tinker. Assignment: For this portion of the final exam, tinker with Python to write the following programs: 1. Print the maximum (the largest number from 10 inputted numbers) 2. Print the sum of 10 inputted numbers 3. Print the average of the 10 inputted numbers Draw a Flowchart of the maximum program: You may draw this using Word, http://draw.io, some other flowchart drawing mechanism, or you may draw it by and take a picture of it. Submission: Create a Word document that has two sections: 1. The Python code for the 3 programs listed above. 2. A picture of the flowchart of the maximum program. Be sure you have appropriate bolded labels before each major section. Create a true header in Word that has you name, Final Exam FlowChart/Python, and the date you completed the work. This will count as two of the four open questions on the final exam.
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Hi! Please check the document. The unique change is that you have to enter your name in the header.If you need modifications contact me.Have a nice day.

Final Exa...


Anonymous
I was stuck on this subject and a friend recommended Studypool. I'm so glad I checked it out!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags