+ All Categories
Home > Documents > curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13....

curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13....

Date post: 03-Jul-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
29
NAF Principles of Information Technology Lesson 13 Introduction to Programming Student Resources Resource Description Student Resource 13.1 Comparison Matrix: Introduction to Computer Code Student Resource 13.2 Reading: Introduction to Computer Code Student Resource 13.3 Keyword Notes: How Programming Languages Work Student Resource 13.4 Reading: How Programming Languages Work Student Resource 13.5 Which Programming Language Should I Learn First? Infographic (Separate File) Student Resource 13.6 Introduction to Programming: Using Python Student Resource 13.7 Reading: The Software Development Process Copyright © 2007–2016 NAF. All rights reserved.
Transcript
Page 1: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information Technology

Lesson 13Introduction to Programming

Student Resources

Resource Description

Student Resource 13.1 Comparison Matrix: Introduction to Computer Code

Student Resource 13.2 Reading: Introduction to Computer Code

Student Resource 13.3 Keyword Notes: How Programming Languages Work

Student Resource 13.4 Reading: How Programming Languages Work

Student Resource 13.5 Which Programming Language Should I Learn First? Infographic (Separate File)

Student Resource 13.6 Introduction to Programming: Using Python

Student Resource 13.7 Reading: The Software Development Process

Copyright © 2007–2016 NAF. All rights reserved.

Page 2: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

Student Resource 13.1

Comparison Matrix: Introduction to Computer CodeStudent Name:______________________________________________________ Date:___________

Directions: Using information in Student Resource 13.2, Reading: Introduction to Computer Code, fill out the matrix below by placing an “x” wherever it is applicable to the items in the left-hand column.

Machine Language

Source Code Assembly Code Compiled Code

Computers can read it

Programmers can read it

High-level program

Low-level program

Copyright © 2007–2016 NAF. All rights reserved.

Page 3: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

Student Resource 13.2

Reading: Introduction to Computer CodeAs you know, the number of tasks computers can perform often seems limitless. But computers aren’t built knowing how to perform these tasks. In fact, computer hardware without software telling it how to function isn’t of any use at all (unless what you need is a doorstop). Computers are stupid—they can do only what we tell them to do. To get the computer to do something, you must tell it in a very precise way—with no errors—using a language the computer understands. You can see this firsthand any time you mistype an email address or URL. One typo will keep your mail from being delivered or keep you from finding your favorite website.

The problem, then, is that people need to be able to give computers very detailed sets of instructions, but the languages that people speak (for example, English or Spanish) are very different from the languages that computers understand. A computer’s microprocessor can only understand one language: the computer’s machine language. This language consists of very detailed and simplistic instructions made up of 0s and 1s. Unfortunately for human programmers, writing a program in machine language is very challenging. It’s like having to build a car out of nuts and bolts rather than car parts. Fortunately, programmers have developed programming languages that are easier to use. Programming languages are classified as “high level” or “low level” depending on the amount of abstraction provided to the programmer (i.e., how easy they are for programmers to use). Machine language is the hardest and “lowest-level” language.

Today, programmers use very high-level languages instead. But if a computer can understand only machine language, what is the value of a different language? The advantage of a higher-level language is that it lets the programmer specify code using “tools” like the preassembled components that manufacturers use to build cars. In order for the computer to understand and run a program written in a high-level language, the program must first be converted into the machine language of the computer. This is done by one of three types of programs: assemblers, compilers, or interpreters.

What Is Computer Code?Computer code is a set of detailed instructions telling a computer’s CPU what to do. This code must be written in the computer’s machine language and free of errors to run correctly (or at all).

When you purchase software programs, they are usually already translated into the computer’s machine language. This means that your computer can execute (or run) these programs, but humans can’t read machine language, so we would not understand the program code.

A programmer writes code using a particular programming language. By “language” we don’t mean a human spoken language such as English. Instead, the term refers to any language that can be used to define a sequence of instructions, or commands, that can be translated for a computer to understand. We call the day-to-day human languages natural languages, while programming languages are artificial languages (these terms are a little misleading in that both types of languages are invented by humans, but programming languages are invented specifically to write computer code). Most programming languages used today look something like English and mathematical notation combined.

The high-level language program written by the programmer is called source code. In other words, source code consists of program instructions in a form that can be read by humans. But computers cannot directly execute source code, so the code must be translated into machine language code, or executable code. As noted above, when you buy computer software, you almost always receive just the machine or executable code. Programs written for an open source platform such as Linux usually provide both the source code and the machine code.

The translation process turns source code into machine code, which consists of a series of 0s and 1s (also called binary code). Programmers use utility programs called assemblers, interpreters, and

Copyright © 2007–2016 NAF. All rights reserved.

Page 4: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

compilers to translate source code into machine code. The difference between these three types of programs depends on what is being translated.

An assembler converts a program written in assembly code into machine language. Assembly code, like machine language code, is very low-level. In fact, one instruction written in assembly code is converted into a single machine language instruction. The difference between the two languages is that while machine language consists of 0s and 1s, assembly language uses terms that can be read. Mostly, these terms are abbreviated in what is known as mnemonics.

Here’s an example of how assembly language works: An instruction that tells the CPU to branch from one location to another in the program might be written as jge next. (The code jge stands for “jump if greater than or equal to.”) This means that if the most recent comparison found that the first value was greater than or equal to (ge) the second value, then the CPU should “jump,” or execute the instruction at location next. The word next is called a label.

In a machine language program, the jge and the label next would be recorded entirely using 0s and 1s. So even though assembly language might be easier to write than machine language, the instructions are still low level, and it makes programming challenging.

Starting in the late 1950s, high-level languages were being pioneered. Today, nearly everyone who writes code uses a high-level language. There are two general schools of thought on converting high-level language programs into machine language. First, and more common, are those languages that use a compiler. The compiler is a program that converts an entire program into machine language at one time. Once the program has been successfully compiled, the executable version of the program can be sold. A positive aspect of compilation is that it only has to take place once. Once compiled, the executable program runs quickly. Also, compilers can locate a type of error in code known as syntax errors.

The other school of thought for converting high-level code: use an interpreter. The idea behind an interpreter is that you can enter one instruction and have it translated and executed. In this way, the programmer can explore what an instruction does, work through ideas, and test each one out. While this helps a programmer develop the code needed to solve the given problem, it has a drawback. Since each instruction is translated before execution, the program must be translated, one instruction at a time, each time the program runs. This slows down execution. The good news about using an interpreter is that most high-level languages that are interpreted also have a compiler. So you can experiment when writing your code, and then you can compile the code when you’re ready.

Copyright © 2007–2016 NAF. All rights reserved.

Page 5: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

Student Resource 13.3

Keyword Notes: How Programming Languages WorkStudent Name:_____________________________________________________ Date:_____________

Directions: Use the following chart to take notes on Student Resource 13.4, Reading: How Programming Languages Work. There are five sections to the reading. After each section, write down the three words that you think will help you remember the most important information in that section. Then move on to the next section and write three more words about that section. Continue this pattern with each of the remaining sections. Based on your keywords, write a summary in the bottom box that includes the important points you observed for each of the sections. Remember that a summary is not a rewrite of the article. Focus only on the key points you need to remember.

Introduction Different Programming Languages

Programming Methods Choosing a Language

The Flow of a Program

Summary

Copyright © 2007–2016 NAF. All rights reserved.

Page 6: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

Student Resource 13.4

Reading: How Programming Languages Work

IntroductionHigh-level programming languages enable people to use familiar words and symbols to tell computers what to do in a way that the computers can understand. Just as human spoken languages have their own grammar and vocabularies, so each programming language has rules for writing commands, and special words and symbols that do different things. If you want to write a program, you choose a programming language (for example, Python or Java) and use its rules and grammar to write instructions, called source code, for the computer. When you are finished, you use another piece of software to turn what you’ve written into something the computer can understand. That software can be either an interpreter or a compiler.Programming, the process of creating computer code, can be compared to writing a cooking recipe. Programs do for computers what recipes do for cooks: they organize data and give instructions for carrying out tasks. Sometimes, these instructions are simply a sequence of unchanging steps. At other times, more complex methods are needed for doing analysis and arriving at decisions.

A typical program consists of a main module and many submodules, sometimes called functions, methods, procedures, or subroutines. These modules are stored as a collection of files. Large programs can contain thousands of individual files, each with a specific purpose. These programs divide big problems into smaller problems. They operate quickly to solve all the smaller problems until the work adds up to one complete solution.

Different Programming LanguagesThere are many different kinds of programming languages. The higher-level a language is, the more it resembles a natural language like English, and the less programmers need to directly concern themselves with the internal workings of the computer hardware. By way of comparison, consider a person who wants to construct a computer. Low-level construction would require that the person use individual circuits to build the computer. With high-level construction, the person would use off-the-shelf components like a specific type of processor and memory circuit boards. At the highest level, the person might order a preassembled computer. Similarly, in programming, we see languages that range from low to high level.

Whether high level or low level, each language has its own set of detailed grammar, spacing, and punctuation rules, just like the rules in languages that people use to communicate with each other. These rules are called syntax. If one of these rules is broken in the program code, the result is a syntax error, because the computer cannot understand the instructions that were given.

Here are some different language types explained:

● The original programming language, machine language, is the language that a computer’s processor understands. Machine language consists of large sets of 0s and 1s. The language is not only challenging because it is difficult to read, but also because the instructions are very low-level. Programming in machine code is not common today because of the use of high-level languages and translation programs like compilers and interpreters. However, the original computer programmers had no choice but to use machine language.

● Assembly is another low-level language. It uses letters and words instead of 0s and 1s in its code, but an assembly programmer still has to know a lot about how the computer’s hardware works. Different versions of assembly language are specific to different types of computers.

Copyright © 2007–2016 NAF. All rights reserved.

Page 7: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

Once an assembly program has been written, the computer cannot yet execute it. Instead, the program must be translated into machine language using a program called an assembler.

● Starting in 1958, high-level languages were being produced. The earliest was called Fortran, a language that made mathematical programming easier than it was with machine or assembly language. Fortran was quickly followed by COBOL, a business processing language. Over the years, high-level languages were improved. A significant language called C was developed in the late 1960s. C offered portability; that is, a program written in C could be compiled not just for the computer it was written for but potentially for any computer. C also introduced more sophisticated programming tools in the form of control statements. Today, we might refer to a language like Fortran, COBOL, or C as a mid-level language. These are high-level languages in that they are far easier to understand than machine or assembly language, but they do not offer as many of the abstraction tools as newer languages do.

● The newer languages have more easily understood terms that make the programmer’s job easier. In 1988, C was expanded to include a new concept known as objects. This ushered in a shift in programming from procedural programming to object-oriented programming. So, C++ lets programmers do things that are difficult when using an assembly language or C. A C or C++ programmer still needs to be aware of things like how the computer’s memory stores numbers and data. These languages are popular in part because they use a computer’s resources efficiently. They also have the advantage of being able to run on many different kinds of processors.

● We would classify C, C++, Fortran, and COBOL as high-level programming languages, but many improved languages have been released in recent years, including Java, C#, and Visual Basic .NET. Added to these are interpreted languages like Perl, Ruby, and Python. These high-level languages are sometimes thought of as higher level than C and C++ because of added features.

Mid- and high-level languages use words and symbols to represent complex concepts simply. This allows a programmer to do more with less effort. Mid- and high-level languages also use familiar math symbols, like the plus and minus signs, to show computer operations. Programs created with high-level languages can direct much more complex tasks than those created with low-level languages. Some high-level languages serve a specific purpose, like creating graphics, while others are very flexible and are considered general purpose. A programmer who needs to write code that will work well with several different operating systems may choose Python or Java. Someone who needs a language that is good at dealing with text may use Perl.

Mid- and high-level languages come with a library of often used functions, called subroutines, that are prewritten to handle simple tasks. This makes the programmer’s job easier.

Programming MethodsAnother way to classify programming languages is by the methods they use to create the program code. For example, the basic element of procedure-oriented programming is the “procedure” (or function or subroutine), which is a sequence of statements that are considered an organizational unit that can accomplish a particular task within the program. Simply put, a procedural language tells the computer how a task is done by breaking the process into small subtasks. Each procedure itself is still a step-by-step sequence of instructions to handle the given subtask. Most of the earliest high-level computer languages (BASIC, Fortran, COBOL, C, Pascal, and so on) were all procedural.

Newer languages made a true break from procedure-oriented programming and are considered nonprocedural. With nonprocedural languages, a programmer defines only what he or she wants the computer to do. It is not necessary to specify how the task should be done.

Copyright © 2007–2016 NAF. All rights reserved.

Page 8: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

Object-oriented programming is organized around “objects” rather than actions. Objects can represent anything from human beings (described by names, addresses, and so on) to buildings, cars, windows in your GUI, icons on your computer’s desktop, and so on. Object-oriented programming (OOP) is focused on the objects the programmer wants to manipulate rather than on the logic used to control them. The first OOP language was called Smalltalk, but the first popularly used OOP language was C++. C++ combined the procedure-oriented programming of C with OOP, so you could write using either programming method. Since that time, newer languages have made better use of OOP, including Java, C#, and Visual Basic .NET. Like C++, some newer languages also combine both procedural and object-oriented characteristics and capabilities, depending on how they are used. Python is another example.

Choosing a LanguageChoosing which programming language to use is important. Every language has advantages and disadvantages, so choosing the best language for a particular situation depends on a number of factors. Use Student Resource 13.5, Which Programming Language Should I Learn First? Infographic (Separate File) to see the type of questions a programmer should ask when choosing to learn or use a programming language.

The Flow of a ProgramPrior to creating the actual source code, a programmer may “map” the program, or a portion of it, by writing an algorithm (a set of instructions explaining how to solve a problem in some abstract way). There are several common approaches to expressing an algorithm. Expressing the algorithm in English terms without necessarily providing the detail of program code is known as using pseudocode. In object-oriented programming, a popular notation is called UML (Unified Modeling Language). Predating both is a diagramming approach called a flowchart. A flowchart is an illustration that uses graphical symbols to illustrate the flow of steps in a process.

The following symbols are commonly used in flowcharts. These symbols are connected by lines with arrows to show the flow from one step to another.

Ovals are used to indicate both the start and end points in a series of steps.

A box is used to represent an individual step or activity in the process.

Yes A diamond shape shows a point in the process when a decision must be made to determine what will happen next. Decisions are denoted as questions with two or more branches indicating the possible results. Usually, these decisions have two branches, one for yes and one for no. Lines extending from diamonds must be labeled with one of these possible answers.

A circle is used to indicate when a particular step is connected to another part or page of the flowchart. A letter is often put inside the circle to help clarify the continuation.

A triangle shows where a measurement is taken during the process.

Conditional statements reflected in a flowchart are used to create source code. Most programming languages use conditional statements such as if...then or if...then...else statements. For

Copyright © 2007–2016 NAF. All rights reserved.

Page 9: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

example, the following is a simple if...then statement about a coffee pot that directs the program to make coffee if the value or variable is equal to empty:

if coffee pot = empty

then make coffee

A variation of this statement can add an else clause:

if coffee pot != empty

then pour a cup of coffee

else make coffee

Note that != means “does not equal.”

This simple flowchart shows how a conditional statement is used to help someone decide whether to go golfing.

Flowcharting can be beneficial to all types of people, not just programmers, because it helps clarify what actually happens or needs to happen in an event or process. You can also use flowcharts to train people (for example, to illustrate what to do in the event of a fire at your school). With a flowchart, it is easier for you to identify problem areas and opportunities for improvement. In fact, while flowcharts are not as frequently used in programming as they used to be, they are used to capture business process models and decision making.

Copyright © 2007–2016 NAF. All rights reserved.

Page 10: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

Student Resource 13.6

Introduction to Programming: Using PythonStudent Name:_____________________________________________________ Date:_____________

We all know how useful computers are. But for a computer to do anything, it needs a computer program. Without programmers, we would not have the programs that make our computers and mobile devices so useful. Many people think that programming is complicated and that program code is hard to understand. While this can be true for complex software, writing simple programs can be easy and fun. Learning how to program is not only rewarding, but it can help you become better in many areas, such as problem solving in mathematics. This hands-on exercise will teach you some basics of programming in the Python language. You will work within an interpreted environment so that you can enter individual commands to see what they do, and later you can put together a program.

Writing PythonDirections: In this exercise, you’ll practice writing Python code in the Python interpreter. Python as a programming language is popular among both hobbyists and professionals. Python programs can be found running on websites as well as on Windows and Linux computers.

We’ll start simply and then keep adding in more elements of code. Keep in mind that any programming requires accurate typing and an exact arrangement of words and symbols. Don’t get frustrated if your code doesn’t do what you expect. Keep trying. If you get stuck or need help, ask your teacher.

When you start Python, a window appears with some introductory text about the version you are running. Also, a prompt appears, waiting for your command: >>>

You will type your code after the >>> prompt. As soon as you hit the Enter key, that code will be interpreted (converted into machine language and executed). The result (if any) will display on the next line.

Specifying a Value The simplest instruction to enter in Python is specifying a value at the prompt, which then becomes the output. Type the following sequence:

● 5 <enter>The number 5 becomes the output.

● 5+2 <enter>Python adds the two numbers, and the output is the number 7.

Copyright © 2007–2016 NAF. All rights reserved.

Page 11: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

● 5*2 <enter>Python multiplies the two numbers, and the output is the number 10.

● 5+2*3 <enter>Notice that the computer obeys mathematical operator precedence rules by computing 2*3 first, before adding 5. The output is the number 11.

StringsA string is a series of characters placed inside quotations marks. You can use either double or single quotes. Try typing "Hello there" <enter>. The output will be:

'Hello there'

VariablesVariables are names attached to memory locations, and they store information for us. For example, we can create a variable called age and another called name. We can then tell the computer to assign a value to the variable. To do this, we use an assignment statement. Type the following sequence:

● age=15 <enter>The number 15 is now stored as the value for the variable age. Notice that nothing is output in response to this instruction (unless you have a typo).

● name="your name" <enter> Use your first and last name in place of your name. Don’t forget the quotation marks and the space between your names. Again, there is no output.

● age <enter>This command does not output age but instead outputs the value stored in the variable age. The number 15 is the output.

● name <enter>You should see your first and last name.

Assignment statements consist of a variable name, an equal sign, and either a value or a computation. Try typing the following assignment statement:

● greeting="Hello "+name <enter> Don’t forget the space after hello but within the quote marks. The + is used to “add” strings

Copyright © 2007–2016 NAF. All rights reserved.

Page 12: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

together (known as string concatenation). In this case, we are creating a string of “hello ” (with a space) and your name combined together, placed into the variable greeting.

Now try typing:

● greeting <enter> You will see what is stored in the variable greeting. The two instructions should look something like the following.

Assignment statements are often used not just to store values but to perform computations. One type of computation is to change a value already stored in a variable. For this, we use a variation of the assignment statement where the variable appears on both the left and right side of the equal sign.

Let’s add 1 to age by using age=age+1. In a program, it means “take the value of age, add 1, and store the result in age.” Try the following sequence:

● age=age+1 <enter>

● age <enter> The output should be the number 16.

Input from the UserNow let’s try adding an input from you, the user, to a variable. The format may look strange, but the word input is actually a call to a function. By using the word input, we are invoking an already written piece of code whose job is to obtain input and return it. What is placed in the parentheses is a prompting message that will appear in the console window before you type in the input. This prompting message is useful for instructing the user on what to do. Type the following sequence:

● name2=input("Enter your name: ") <enter>We take the value returned and store it in the variable name2. Make sure you type the instruction exactly as shown, including two blank spaces after the colon (:) following the word name.

● After entering the above command, you will see 'Enter your name: ' in the console window. At this point, type a friend’s name and press the Enter key. You will not see any output.

● Another function is called print. Although we can output the value of a variable just by typing in the variable name, the print function is more useful in that we can use it to output a number of things. Type the following. Notice that there is a blank space after the word is. There are no blank spaces following the word print, the second quotation mark symbol, or the plus sign.

1. print("My friend is "+name2) <enter>

What do you see?

Copyright © 2007–2016 NAF. All rights reserved.

Page 13: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

If-Statements and If/Else-StatementsAnother feature of a program is to decide what should be done based on values stored in variables. For instance, we might want our program to decide and tell us if, based on our age, we should go to recess or to the library. To make a decision, programs use if-statements and if/else-statements. In Python, the syntax is a little bit odd and requires using proper indentation. Type the following after the prompt (>>>), and make sure you use the Tab key to indent when needed. The prompt and the ellipses (…) are automatically displayed; they are not something for you to type.

● >>> if age >= 15: <enter>

● ... print("Go to the library and study") <enter>

● ... else: <enter>

● ... print("Go play at recess") <enter>

● ...<enter>

The result should be either the message about going to the library or the message about recess, depending on the value stored in age. Since age should now be 16, the message should tell you to go to the library and study. Notice that the notation >= means “greater than or equal to.”

Now try this. Type:

● age=14 <enter> Now retype the if-then-else statement above.

What output did you get this time? Notice how the computer makes a choice of what to do. The if-then-else statement is a very powerful tool that we use throughout a program. These statements allow the program to make decisions on its own.

For-LoopsAnother type of feature of a program is known as a loop. A loop causes a set of code to operate a certain number of times. Several types of loops exist, but we will look only at one type of loop in Python called an iterator loop. This loop, known as a for-loop, will iterate once for each item in a list. Let’s try it out with the following code. Make sure to press the Tab key for the second line, and remember that the ellipses (…) are automatically placed there, so do not type them yourself.

● >>> for number in [0, 1, 2, 3, 4]: <enter>

● ... print(number) <enter>

● ...<enter>

2. This will print 0, 1, 2, 3, and 4 on separate lines.

Copyright © 2007–2016 NAF. All rights reserved.

Page 14: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

The for-loop can operate on lists that contain numbers, strings, and individual characters. Type the following two for-loops, adding a tab for each second line:

● >>> for item in [1, 10, 'a', 'abc']: <enter>

● ... print(item) <enter>

● ... <enter>

● >>> for item in name: <enter>

● ... print(item) <enter>

● ... <enter>

What do you see? (Remember that for our example, the variable name had Emily Smith stored in it. Your variable name should have your own name.)

Another function is called range( ). This function returns a list of all of the numbers in the range from 0 to one less than the number you place in parentheses ( ). Type the following:

● for number in range(5): <enter>

Copyright © 2007–2016 NAF. All rights reserved.

Page 15: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

● ... print(number) <enter>

● <enter>

And you will see, 0, 1, 2, 3, 4 print out. You can also specify the starting point for a range. Retype the previous code but use range(1,6) and you will get the numbers 1 through 5 as output. Let’s use this idea to perform a computation called a factorial. A factorial is the value we get by multiplying a number by all of the numbers less than it down to 1. For instance, the factorial for 5 is 5*4*3*2*1. We write this value as 5!. The following code computes and outputs 5!. Remember to include the tab in the third line.

● factorial=1 <enter>

● for value in [1, 2, 3, 4, 5]: <enter>

● ... factorial=factorial * value <enter>

● <enter>

● print(factorial) <enter>

The result should be 120.

Challenge Activity: FunctionsA function is a piece of code that you can invoke over and over again. So the idea here is that you will build a program by writing a sequence of functions and saving them to disk file. We will write and test our function but not save it.

A defined function will look like this at the prompt:

>>> def age( ):

There is a space between the parentheses. This function is now called age.

Now each line that follows will be the instructions that make up that function. A few key points to remember:

1. Indent at the beginning of each line by pressing the Tab key.

2. Press Enter at the end of each line except after the first def age ( ): line. (Notice that as we saw with the if/else-statements and for-loop statements, the prompt changes from >>> to ....)

3. Notice that two tabs are needed at the beginning of lines 8 and 11. (These are the lines after the if-statement and the for-loop.)

4. After you have entered the last command for the function, hit the Enter key twice.

Type the following program. (For year and yourBirth, use the current year and your birth year rather than what is listed.)

● def age( ):

● <tab> name=input("What is your name? ") <enter>

● <tab> year=2015 <enter>

● <tab> yourBirth=2000 <enter>

Copyright © 2007–2016 NAF. All rights reserved.

Page 16: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

● <tab> birthday=input("Have you had a birthday yet this year? Y or N? ") <enter>

● <tab> yourAge=year-yourBirth <enter>

● <tab> if birthday=='N': <enter>

● <tab> <tab> yourAge=yourAge-1 <enter>

● <tab> print(name+", your age is") <enter>

● <tab> for number in range(yourAge): <enter>

● <tab> <tab> print(number) <enter>

● <tab> print(yourAge) <enter>

● <enter>

Remember if you receive errors at any point, retype the function definition from the start. It may take you several attempts before you have it correctly entered.

When you are done, type:

age( ) <enter>

Answer the questions for your name and birthday as prompted. Run the function two times, answering once with Y and once with N to make sure you get the proper output. Notice how you can write a function and then use it over and over.

To make the function age( )even more interesting, you could ask the user to enter his or her birth year using yourBirth=("Enter the year you were born: ") <enter> in place of the command that set yourBirth to a set year (2000, in our example). If you want to, try to rewrite the above function with this new statement. Now, every time you run the program, use a different combination of your birth year and whether you have had a birthday or not.

Congratulations! You just coded some of your own simple computer programs! Show your teacher the output when you are done.

Copyright © 2007–2016 NAF. All rights reserved.

Page 17: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

Student Resource 13.7

Reading: The Software Development Process

Copyright © 2007–2016 NAF. All rights reserved.

Page 18: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

In the earliest days of computing, software development was simply a single programmer writing code in order to solve a problem or computerize a process. However, today’s computer systems are so large and so complex that a team of people is commonly needed to build a successful software product.

A software development team can include product managers, project managers, systems analysts, software designers, programmers, testers, graphic designers, marketers, technical writers, and even software users like you to test the product. A set of agreed-upon principles, methods, and tools are used to coordinate the team’s efforts so that the software project meets its goals.

Copyright © 2007–2016 NAF. All rights reserved.

Page 19: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

To help manage the software development process, the software development life cycle (SDLC) was created. The SDLC is an organized way to build a software system or product. Although some development teams break down the steps in the SDLC in slightly different ways, the following phases are typical:

Write the problem statement: This phase establishes a big-picture view of the intended project and determines its goals. This process may involve software users (called end users) who provide ideas for improving the project. This phase also includes conducting preliminary research to see whether the proposed solution is cost effective.

Write the requirements: This phase is for analyzing the needs of end users and translating project goals into specific, practical requirements.

Design the first version of the program: In this phase, developers describe in detail all the features and operations of the system or product to meet the needs defined in the planning phase. The design serves as a type of blueprint for the project and helps detect potential problems in the plan before programming is started. This phase often includes the creation of a prototype that shows how screens will look and how processes will flow.

Code/test/fix the first version: This phase involves the writing and debugging of code to create an alpha (first) version of the software.

Copyright © 2007–2016 NAF. All rights reserved.

Page 20: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

Design the next version of the program: After adjustments are made to the alpha version, a beta (second) version is designed. End users often play a key role by helping to test the system or product in this phase.

Code/test/fix the next version: In this phase, the beta code is created, tested, and fixed. At this point, an independent quality-assurance group may be employed to try to break the code. These people usually start by asking the question, “If I don’t do what the program asks, what happens?”

Deploy/maintain/evaluate the first code release and plan for the next release: After final adjustments have been made to the beta version, what is sometimes called a “gold master” is put into production (manufactured) and released to the public (or to a specific customer) for installation and actual use. Then planning begins for the next product release.

Copyright © 2007–2016 NAF. All rights reserved.

Page 21: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

This process is iterative—in other words, after you complete step 7, you need to “circle back” and work through the steps again, starting with step 1. In a commercial programming organization, the process continues to iterate as long as the software product is supported in the marketplace. Rarely is a program released to the public without some undiscovered bug.

When you illustrate an iterative process, you need to be sure you show the iteration graphically. For example, if you used flowcharting to illustrate the software development process, you might draw or print an arrow starting from step 7 and going back up to step 1.

Copyright © 2007–2016 NAF. All rights reserved.

Page 22: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

The following are examples of mistakes that can cause a project to fail:

• Not defining the problem statement or the project requirements clearly and accurately

• Not getting everyone concerned with the project to agree on the problem statement or project requirements

• Not adequately identifying or distributing resources among team members

• Not properly tracking the progress of the project, in terms of cost and schedule

• Not identifying or addressing potential threats to the success of the project—in other words, not gathering enough information and/or ignoring potential problems

• Iterating only once through the process—for example, not gathering customer feedback on a software product already in the field and adjusting future product plans to customer requirements

Copyright © 2007–2016 NAF. All rights reserved.

Page 23: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

The following are some generally accepted tips to use when developing software:

• Be very thorough in gathering product requirements, and document them in writing. Make sure that all those involved with the project agree on these requirements.

• Break large tasks into smaller, manageable pieces, and identify deadlines for each.

• To ensure accountability from all team members, make sure that deadlines are clear and that people are required to report regularly on their progress.

• Include procedures throughout the project for monitoring and maintaining quality. This includes frequent testing. Peer review, a process used for checking work by one’s own equals or peers, is a good idea.

• Keep control of your project, but not too rigidly—change is a part of life, and that includes software development.

• After the project is completed, ask the team to reflect on the project to identify what worked well and what should have been done differently. This information can be helpful for future projects.

Copyright © 2007–2016 NAF. All rights reserved.

Page 24: curriculum.naf.orgcurriculum.naf.org/packaged/assets/downloads/shared/pr…  · Web viewLesson 13. Introduction to Programming . Student Resources. Resource: Description ; Student

NAF Principles of Information TechnologyLesson 13 Introduction to Programming

When the source code (programming instructions) for a software product is made available to users and other developers, we refer to that software as open source software. The open source movement started because some developers thought that software products could be made better if companies and programmers worked together. Those who distribute open source software expect and encourage others to examine the source code to find problems and to make changes to improve the product. The Linux operating system and a lot of the Linux application software are examples of open source software.

The availability of open source software has influenced software development in another way. Companies who develop proprietary software (software whose source code is not publicly available) have to work a little harder to keep their share of the computer market, because people now have open source alternatives.

Copyright © 2007–2016 NAF. All rights reserved.


Recommended