Podcast
Questions and Answers
What should be done before writing code in the program development cycle?
What should be done before writing code in the program development cycle?
- Testing the program
- Correcting syntax errors
- Correcting logic errors
- Designing the program (correct)
Which of the following is the most important part of the program development cycle?
Which of the following is the most important part of the program development cycle?
- Correcting syntax errors
- Writing the code
- Testing the program
- Designing the program (correct)
What is the definition of an Algorithm?
What is the definition of an Algorithm?
- A diagram that graphically depicts the steps in a program.
- Set of well-defined logical steps that must be taken to perform a task. (correct)
- Informal language that has no syntax rule.
- A variable that can only be assigned integer values.
What is pseudocode primarily used for?
What is pseudocode primarily used for?
Which symbol represents processing in a flowchart?
Which symbol represents processing in a flowchart?
In the typical three-step process performed by computers, what follows after receiving input?
In the typical three-step process performed by computers, what follows after receiving input?
What is the purpose of the print
function in programming?
What is the purpose of the print
function in programming?
How are string literals defined in Python?
How are string literals defined in Python?
Which character is used to begin a comment in Python?
Which character is used to begin a comment in Python?
What is a variable in programming?
What is a variable in programming?
Which of the following is a valid variable name in Python?
Which of the following is a valid variable name in Python?
What happens when multiple items are passed to the print
function in Python?
What happens when multiple items are passed to the print
function in Python?
What is 'garbage collection' in Python?
What is 'garbage collection' in Python?
What does it mean when a variable is reassigned in Python?
What does it mean when a variable is reassigned in Python?
Which data type is used for storing strings in memory?
Which data type is used for storing strings in memory?
What happens if you try to convert a non-numeric string to an integer using the int()
function?
What happens if you try to convert a non-numeric string to an integer using the int()
function?
What is the result of the expression 10 / 3
in Python?
What is the result of the expression 10 / 3
in Python?
Which operator is used to return the remainder of a division?
Which operator is used to return the remainder of a division?
What is the order of operations in Python?
What is the order of operations in Python?
What is the purpose of the exponent operator **
?
What is the purpose of the exponent operator **
?
If you multiply two int
values, what will the resulting data type be?
If you multiply two int
values, what will the resulting data type be?
If you add an int
and a float
, what will the resulting data type be?
If you add an int
and a float
, what will the resulting data type be?
What happens when you convert a float
to an int
?
What happens when you convert a float
to an int
?
How can a long statement be broken into multiple lines in Python?
How can a long statement be broken into multiple lines in Python?
How does print
function display the output by default?
How does print
function display the output by default?
What will be the output of the code, print('line1 \n line2')?
What will be the output of the code, print('line1 \n line2')?
Which type of data will input()
function return?
Which type of data will input()
function return?
Which of the following is the proper way to concatenate strings in Python?
Which of the following is the proper way to concatenate strings in Python?
What are “magic numbers” in programming?
What are “magic numbers” in programming?
What is the main problem associated with using magic numbers in code?
What is the main problem associated with using magic numbers in code?
Why should named constants be used instead of magic numbers?
Why should named constants be used instead of magic numbers?
What happens if you enclose any part of a statement in parentheses?
What happens if you enclose any part of a statement in parentheses?
If the variable number
has the value 123.4567
, what would format(number, '.2f')
return?
If the variable number
has the value 123.4567
, what would format(number, '.2f')
return?
Consider this line of code:
print('Total: $' + format(1000, ',.2f'))
What exactly is happening when +
is used in this context?
Consider this line of code:
print('Total: $' + format(1000, ',.2f'))
What exactly is happening when +
is used in this context?
What will be printed when the below code is executed?
num1 = 10
num2 = 3
print(num1 % num2)
What will be printed when the below code is executed?
num1 = 10
num2 = 3
print(num1 % num2)
What is the result of the following expression in Python? python 2 + 3 * 4 ** 2 / 2 - 10
What is the result of the following expression in Python? python 2 + 3 * 4 ** 2 / 2 - 10
Given:
x = 5
y = '7'
z = x + int(y)
print(z)
What value will then be printed for z
?
Given:
x = 5
y = '7'
z = x + int(y)
print(z)
What value will then be printed for z
?
Flashcards
Program design
Program design
Programs must be designed before writing code.
Program development cycle
Program development cycle
Design, write, correct syntax and logic, test.
Importance of design
Importance of design
Most important part of program development, understand the task, software requirements.
Algorithm
Algorithm
Signup and view all the flashcards
Pseudocode
Pseudocode
Signup and view all the flashcards
Flowchart
Flowchart
Signup and view all the flashcards
Input, Processing, Output
Input, Processing, Output
Signup and view all the flashcards
Print function
Print function
Signup and view all the flashcards
Argument
Argument
Signup and view all the flashcards
String
String
Signup and view all the flashcards
String literal
String literal
Signup and view all the flashcards
Comments
Comments
Signup and view all the flashcards
End-line comment
End-line comment
Signup and view all the flashcards
Variable
Variable
Signup and view all the flashcards
Assignment statement
Assignment statement
Signup and view all the flashcards
Variable Naming Rules
Variable Naming Rules
Signup and view all the flashcards
Displaying Multiple Items with the print Function
Displaying Multiple Items with the print Function
Signup and view all the flashcards
Variable Reassignment
Variable Reassignment
Signup and view all the flashcards
Garbage collection
Garbage collection
Signup and view all the flashcards
Data types
Data types
Signup and view all the flashcards
Numeric literal
Numeric literal
Signup and view all the flashcards
input function
input function
Signup and view all the flashcards
int() function
int() function
Signup and view all the flashcards
float() function
float() function
Signup and view all the flashcards
Math Operator
Math Operator
Signup and view all the flashcards
Operands
Operands
Signup and view all the flashcards
/ operator
/ operator
Signup and view all the flashcards
// operator
// operator
Signup and view all the flashcards
Python operator precedence
Python operator precedence
Signup and view all the flashcards
Exponent operator (**)
Exponent operator (**)
Signup and view all the flashcards
Remainder operator (%)
Remainder operator (%)
Signup and view all the flashcards
Breaking Long Statements into Multiple Lines
Breaking Long Statements into Multiple Lines
Signup and view all the flashcards
Print Function
Print Function
Signup and view all the flashcards
string literal
string literal
Signup and view all the flashcards
Built in format function
Built in format function
Signup and view all the flashcards
Magic Number
Magic Number
Signup and view all the flashcards
Named Constant
Named Constant
Signup and view all the flashcards
Study Notes
Designing a Program
- Programs must be designed before they are written
- The program development cycle consists of; design, writing code, correcting syntax errors, testing the program, and correcting logic errors
- Design is the most important part of the program development cycle
- Understand the task of the program, working with the customer and creating software requirements
Algorithm
- Determine the steps to perform the task by breaking it down into a series of steps
- An algorithm is a set of well-defined logical steps to perform a task
Pseudocode
- Pseudocode is fake code written in an informal language with no syntax rules
- Informally models programs without compilation or execution, and is translated into actual code in any programming language
- Focus should be on program design without worrying about syntax errors
Flowcharts
- Flowcharts are diagrams that graphically depict the steps in a program
- Ovals are terminal symbols
- Parallelograms are input and output symbols
- Rectangles are processing symbols
- Symbols are connected by arrows represent the flow of the program
Input, Processing, and Output
- A computer typically performs the three step process of input, processing, and output
- Input is any data that the program receives while it is running, such as mathematical calculations
- Output is a result of the process of the input
Print Function
- A function is a piece of prewritten code that performs an operation
- A print function displays output on the screen
- An argument is data given to a function, used like examples for what is printed
- Statements in a program will execute in the same order that they appear
Strings and String Literals
- Strings are sequences of characters used as data
- String literals are strings represented in a program's code
- String literals must be enclosed in single (') or double (") quote marks
- String literals can be enclosed in triple quotes (''' or """)
- Enclosed strings can contain both single and double quotes and can have multiple lines
Comments
- Comments are notes of explanation within a program, which are ignored by Python and intended for a person reading the program's code
- Comments begin with a # character
- An end-line comment appears at the end of a line of code, typically explaining the purpose of that line
Variables
- Variables are names that represents a value stored in the computer memory, used to access and manipulate data stored in memory
- A variable references the value it represents
- An assignment statement is used to create a variable and make it reference data using a general format
- variable = expression, for example age = 29, where (=) is the assignment operator
Variable Assignments
- In an assignment statement, a variable receiving a value must be on the left side
- A variable can be passed as an argument to a function, with the variable name not enclosed in quote marks
- A variable can only be used if a value is assigned to it
Variable Naming Rules
- The rules for naming variables in Python are that; variable names cannot be Python key words, cannot contain spaces, the first character must be a letter or underscore, after the first character letters/digits/underscores are allowed, and variable names are case sensitive
- Variable names should reflect their use
Print Function Calls
- Python permits displaying multiple items with a single call to print
- Items are separated by commas when passed as arguments
- The arguments are displayed in the order they are passed to the function
- Items are automatically separated by a space when displayed on a screen
Variable Reassignment
- Variables can reference different values while the program is running
- Garbage collection removes used values that are no longer referenced by variables via the Python interpreter
- Variables can refer to items of any type, even if they have been assigned to a specific one
Data Types
- Data types categorize values in memory
- Int is for integer, float is for real numbers, and str is used for storing strings
- A numeric literal is a number written in a program
- Numbers with no decimal point are considered int, otherwise they are considered float
- Some operations behave differently depending on data type
Reassigning Types
- Variables in Python can refer to items of any type
Keyboard input
- Most programs require reading input from the user
- The built-in input function is used when reading input from a keyboard
- All input is returned as string data
- Variable = Input (Prompt) format
- Value is typically a string prompting the user to value
Input Function
- The input function always returns a string
- Built in functions convert between data types
- int(item) converts an item to an int
- float(item) converts an item to a float
- Nested function calls follow the Function1 (Function2 (Argument)) format
- Value returned by Function 2 is passed to Function 1
- Type conversion only works if the item is a valid numeric value, otherwise an exception is thrown
Calculations
- The Math expression performs calculations and gives a value
- Math operators is the tool used, operating on the surrounding variables
- The resulting value is typically assigned to a variable
- Regular division "/" is a floating point
- Integer division "//" truncates
Operator Precedence
- Python operator precedence is as follows
- Operations enclosed in parentheses
- Exponentiation (**)
- Multiplication (*), division (/ and //), and remainder (%)
- Addition (+) and subtraction (-)
- Higher precedence is performed first, with same level proceeding from left to right
Exponents and Remainders
- Exponent operator (**) raises a number to a power
- Remainder operator (%) performs division operations and returns the remainder
- Also known as a modulus operator
- They can convert times and distances, or to detect odd or even numbers
Long Statements
- Long statements cannot be viewed on screen without scrolling and cannot be printed without cutting them off
- Multiline continuation character () allows you to break a statement into multiple lines
- Any part of a statement enclosed in parentheses can be broken without the line continuation character
Data Output
- The print function displays lines of output end= ' delimiter' replaces new lines in output data
- sep='delimiter' replaces item separation in output data
String Operations
- Special characters appearing in a string literal are preceded by a backslash ()
- Examples are newline (\n), horizontal tab (\t)
- The + operator performs string concatenation
Number Formats
- You can format display of numbers on the screen using the built in format function
- It requires two items including; Numeric value to be formatted and a Format specifier
- Returns string containing formatted number
- Format specifier typically includes precision and data type
- Scientific notation, comma separators, and the minimum field used to display the value
Integers as Formats
- The % symbol can be used in the format function to format a number as a percentage
- To format an integer using the format function do not specify precision
- Use "d" as the type designator, and still use format function to set field width or comma separator
Magic Numbers
- A magic number is an unexplained numeric value that appears in a program's code
- It is difficult to determine the purpose of the number
- If this type of value needs to be changed it must be modified in every place it is used
- There is a risk of making a mistake each time you type in the value
Named Constants
- Named constants should be used instead of magic numbers
- Named constant is a name representing a value that does not change during the program's execution
Constant Advantages
- They make code self-explanatory
- Help to make code easier to maintain
- Help prevent typographical errors associated with manual entry
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.