Chapter 2: Input, Processing, and Output Flashcards

1
Q

Stages of “The Program Development Cycle”:

A
  1. Design the Program
  2. Write the Code
  3. Correct Syntax Errors
  4. Test the Program
  5. Correct Logic Errors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a SYNTAX ERROR?

A

Mistake such as: misspelled key word, missing punctuation, or incorrect use of an operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a LOGIC ERROR?

A

Mistake that does not prevent the program from running but causes it to produce incorrect results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is PSEUDOCODE?

A

An informal language that has no syntax rules and is not meant to be compiled or executed.
Used by programmers to create models, or “mock-ups” of programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a FLOWCHART?

A

Diagram that graphically depicts the steps that take place in a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Computer programs typically perform a 3 Step Process:

A
  1. INPUT is received
  2. Some PROCESS is performed on the input
  3. OUTPUT is produced
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Print Function

A

Used to display output on the screen.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Print function SYNTAX:

A

STRING/STRING LITERAL (str) must be enclosed in a pair of quote marks-

print(‘argument’)

> > > print(‘Hello World’)
Hello world

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

comments

A

Notes of explanation that document lines or sections of a program.

  • part of the program, but ignored by Python interpreter
  • intended for people reading source code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Variable

A

A name that references a value in the computer’s memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Assignment statement

& operator

A

Used to create variable and make it reference a piece of data

 variable = expression
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

print(the value stored in a variable)

A
>>> width = 10
>>> length = 5
>>> print(width)
10
>>> print(length)
5
>>> print(length, width)
10 5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

VARIABLE Naming Rules

A
  1. Cannot use a Python key word
  2. Cannot contain spaces
  3. First character must be: a-z, A-Z, or an underscore_
  4. After first char., may use: a-z, A-Z, 0-9, or underscores_
  5. Upper & lower case char.’s are distinct
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

camelCase naming convention

A

variableName begins with lower case letters & the first char. of the second and subsequent words written in uppercase-

camelCaseNamingConvention

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Python allows display of multiple items with one call to the print function by:

A

Separating items with a comma-

firstName = ‘Jane’
lastName = ‘Doe’
»> print(firstName, lastName)
Jane Doe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A number written into a program’s code is called a NUMERIC LITERAL.

Because TYPES of numbers are stored and manipulated in different ways, Python uses data types to categorize values in memory-
3 data types:

A
  1. int - a numeric literal written as whole number with no decimal is considered as an integer. (7, 124, -9)
  2. float - a numeric literal written with a decimal is considered a float. (1.5, 5.0)
  3. str - used for storing strings in memory. ( number = 3 or number = ‘three’ or number = ‘The number 3 is spelled, three’
17
Q

Variable reassignment

A
>>> number = 3
>>> print(number)
3
>>> number = ‘three’
>>> print(number)
three
18
Q

Input function

A

Programs commonly need to read input typed by the user on the keyboard.

Normally used as in an assignment statement, following the general format:
variable = input(prompt)

> > > name = input(‘Enter your name: ‘)
Enter your name: Jane
print(name)
Jane

User INPUT is returned to the program as a STRING

19
Q

To perform math operations on numeric data entered by the user with the input() you need to first, convert the data from str, to int or float:

A

> > > stringValue = input(‘How many hours did you work? ‘)
hours = int(stringValue)

Or more efficiently, use the NESTED FUNCTION -
»> hours = int(input(‘How many hours did you work? ‘))

20
Q

Write a program that asks the user to enter 3 different data types- their name (str), age (int), & income (float) and returns the user entered data as:

Here is the data you entered:
Name: Jane
Age: 25
Income: 7500.0

A

> > > name = input(‘Enter your name: ‘)
age = int(input(‘Enter your age: ‘))
income = float(input(‘Enter your income: ‘))
print(‘Here is the data you entered: ‘)
print(‘Name: ‘, name)
print(‘Age: ‘, age)
print(‘Income: ‘, income)

21
Q

What result is returned on:

> > > 3*3

> > > ‘3’ *3

A

> > > 3*3
9
‘3’ *3
333

22
Q

In the following, which are the math expression, the operands, and the operator?

> > > 12 + 2

A

math expression: 12+2

operands: 12 and 2
operator: +

23
Q

Python Math Operators

A

+ Addition
- Subtraction
* Multiplication
/ Division (gives result as a float)
// Integer Division (gives result as a whole number)
% Remainder (divides #s and gives the remainder)
** Exponent

24
Q

Operator Precedence:

A

First: operations enclosed in ( ) are performed
Next: exponents **
Then: multiplication, division, and remainder * / // % (from L to R)
Last: addition and subtraction + - (from L to R)

25
Q

average = (test1 + test2 + test3) / 3

Write a program to calculate the average from data entered by user

A

> > > test1 = float(input(‘First test score: ‘))
test2 = float(input(‘Second test score: ‘))
test3 = float(input(‘Third test score: ‘))
average = (test1 + test2 + test3 ) / 3
print(‘The average grade is:’, average)

26
Q

Operations performed on 2 int values will return the value as an int.
Operations performed on 2 float values will return the value as a float.
What will happen to operations performed on an int and a float?
»>5*2.0

A

The int value will be temporarily converted to a float and the result of the operation will be a float. The result is:
10.0

27
Q

Expressions that use operands of different data types are called__________.

A

Mixed-Type Expressions

28
Q

Python’s Escape Characters:

A
\n     advances output to the next line
\t      output skips over to the next horizontal tab position
\'      causes a ' mark to be printed
\"     causes a " to be printed 
\\     causes a \ to be printed
29
Q

Suppressing the Print( ) Ending New Line:

A

> > > print(‘One’, end =’ ‘)
print(‘Two’, end =’ ‘)
print(‘Three’)
One Two Three

> > > print(‘One’ , ‘Two’ , ‘Three’ , sep = ‘~~~’)
One~~~Two~~~Three

30
Q

Displaying Multiple Items with the + Operator:

STRING CONCATENATION

A

> > > print(‘This is ‘ + ‘one string.’)
This is one string.

> > > print(‘Enter the amount of ‘ +
‘sales for each day and ‘ +
‘press Enter.’)
Enter the amount of sales for each day and press Enter.

31
Q

When to expression returns the value:
pi = 3.1415926
How do you format the number to return:
pi = 3.14

A

> > > print(format(3.1415926, ‘.2f’))

3.14