Introduction to Computers and Programming-Input, Processing, and Output (IPO)- Overview
One important principle in computer programming is to create a plan a design before actually starting to write the code for the program
Programs must be carefully designed before they are written. During the design process, programmers use tools such as pseudocode and flowcharts to create models of programs.
The Program Development Cycle
The entire process for developing software is known as the program development cycle. If your program is designed poorly, eventually you will find yourself doing a lot of work to fix the program.
Flow Charting
Flow charting is another tool that programmers use to design programs. A flowchart is a diagram that graphically depicts the steps that take place in a program. In class, we will review Microsoft Visio and Word as a tool to create flowcharts
Pseudo Code
Flow charting is another tool that programmers use to design programs. A flowchart is a diagram that graphically depicts the steps that take place in a program. In class, we will Word as a tool to create Pseudo Code
Input. Processing, Output (IPO)
Input is data that the program receives. When a program receives data, it usually processes it by performing some operation with it. The result of the operation is sent out of the program as output.
It is important to understand that the statements in a program execute in the order that they appear, from the top of the program to the bottom. When you run a program, the first statement will execute, followed by the second statement, and followed by the third statement. This is referred to as a linear sequence
Data Types
Below are a few of the fundamental data types in computer technology
String
Boolean
Integer
Floating Point Number
Comments
Comments are notes of explanation that document lines or sections of a program. Comments are part of the program, but the Python interpreter ignores them. They are intended for people who may be reading the source code. In Python you begin a comment with the # character. When the Python interpreter sees a # character, it ignores everything from that character to the end of the line.
Creating Variable
A variable is a name that represents a value stored in the computer’s memory. Programs usually store data in the computer’s memory and perform operations on that data. In computer programming programmers use variable to hold data and information for processing. While designing programs, we will be using variables to hold input and the result of arithmetic expressions. You use an assignment statement to create a variable and make it reference a piece of data.
Variable Naming Rules
Although you are allowed to make up your own names for variables, you must follow these rules:
Variable Reassignment
Variables are called “variable” because they can reference different values while a program is running. When you assign a value to a variable, the variable will reference that value until you assign it a different value. When a value in memory is no longer referenced by a variable, the Python interpreter automatically removes it from memory through a process known as garbage collection
Reading Input from the Keyboard
So far you have been assigning data internally and literally to variables. Programs commonly need to read input typed by the user on the keyboard. We will examine and use a Python functions to do this.
Most of the programs that you will write will need to read input and then perform an operation on that input
The input() function reads a piece of data that has been entered at the keyboard and returns that data, as a string, back to the program.
The input function always returns the user’s input as a string, even if the user enters numeric data.
Python has built-in functions that you can use to convert a string to a numeric. They are type casting functions with the capability to transfer a string data type into numeric data types
Arithmetic Operators in Python
+ Addition Adds two numbers
− Subtraction Subtracts one number from another
* Multiplication Multiplies one number by another
/ Division Divides one number by another and gives the result as a floating-point number
// Integer division Divides one number by another and gives the result as an integer
% Remainder Divides one number by another and gives the remainder
** Exponent Raises a number to a power
Grouping with Parentheses
Parts of a mathematical expression may be grouped with parentheses to force some operations to be performed before others. Similar to an algebraic expression
Breaking Long Statements into Multiple Lines
Most programming statements are written on one line. If a programming statement is too long, however, you will not be able to view all of it in your editor window without scrolling horizontally. In addition, if you print your program code on paper and one of the statements is too long to fit on one line, it will wrap around to the next line and make the code difficult to read. Python allows you to break a statement into multiple lines by using the line continuation character, which is a backslash (\). You simply type the backslash character at the point you want to break the statement, and then press the Enter key.
Python recognizes several escape characters, some of which are listed below
\n Causes output to be advanced to the next line.
\t Causes output to skip over to the next horizontal tab position.
\' Causes a single quote mark to be printed.
\" Causes a double quote mark to be printed.
\\ Causes a backslash character to be printed.
Use these escape characters to assist you in formatting your screen and printed output
Format Specifier
When you call the built-in format function, you pass two arguments to the function: a numeric value and a format specifier. The format specifier is a string that contains special characters specifying how the numeric value should be formatted. Make sure to review the section in chapter 2 covering Format Specifier. Use format specifier to assist you in formatting your screen and printed output