1/44
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Simple Decision Structure
In a decision structure, some condition must be tested before some action can be performed.
Boolean Variables
The if clause asks a question, which is a boolean statement resulting in a boolean value: True or False.
Relational Operators
Boolean expressions can be built using relational operators such as <, >, <=, >=, ==, and !=.
Comparing Strings
The relational operators can also be used to compare strings using their ASCII codes.
If / Else Decision Structure
Sometimes, we want to do one thing if the condition is true and something else if the condition is not true.
Nested Conditional Statements
Multiple conditions are tested one after the other to make different decisions.
Logical Operators
Boolean expressions can be built using logical operators such as and, or, and not.
Assignment Operator
= is the assignment operator.
Comparison Relational Operator
== is the comparison relational operator.
ASCII Code
The ASCII code is used to compare two strings.
Example: Average.py
An example program demonstrating the use of averages.
Example: Overtime.py
An example program demonstrating the use of if/else decision structure.
Example: LoanQualifier.py
An example program demonstrating nested conditional statements for loan qualification.
Boolean Value
The result of a boolean question is a boolean value, either True or False.
Condition Testing
In a decision structure, some condition must be tested before some action can be performed.
True
A boolean value indicating a positive condition.
False
A boolean value indicating a negative condition.
Example: Salary Qualification
Does a person qualify for a loan? Salary >= 30000 and Years with job >= 2.
Result of Logical Operators
Result is true if both conditions are true for 'and', true if either condition is true for 'or', and true if the condition is false for 'not'.
Condition Structure
Using an 'and' operator creates a different nested conditional structure.
Loan Qualification Criteria
Salary < 30000 or Salary >= 30000 and Years with job >= 2
Minimum Salary Requirement
You must earn at least $30,000 to qualify
Minimum Job Duration Requirement
You must be on your current job for at least two years to qualify
Wi-Fi Diagnostic Tree
A flowchart used to troubleshoot Wi-Fi connection issues
Rebooting Process
Reboot the computer and try to connect; if that doesn't fix the problem, reboot the router and try again
Cable Check
Make sure the cables between the router and modem are plugged in firmly
Router Relocation
Move the router to a new location and try to connect
Order of Operations
Highest: *, , /, %, +, -; Lowest: <, <=, >, >=, ==, !=, not, and, or
if-elif-else Statement
Allows to sometimes do something and other times do another thing while many conditions are tested
elif
An abbreviation for 'else if', used to specify a new condition if the previous conditions are false.
random module
A module in Python that provides functions to generate random numbers.
random.random()
Generates a random floating-point number in the interval [0, 1).
random.randint(a, b)
Generates a random integer in the interval [a, b], inclusive.
Random number generation formula
To generate a random number in the interval [a, b), use: floatNumber = random.random() * (b - a) + a.
.lower() method
A string method that converts all letters in a string to lowercase.
.upper() method
A string method that converts all letters in a string to uppercase.
.capitalize() method
A string method that changes the first letter of a string to uppercase.
.title() method
A string method that changes the first letter of each word in a string to uppercase.
.isalnum() method
A string method that checks if all characters in a string are letters or digits.
.isalpha() method
A string method that checks if all characters in a string are letters.
.isdigit() method
A string method that checks if all characters in a string are digits.
.islower() method
A string method that checks if all letters in a string are lowercase, ignoring non-letter characters.
.isupper() method
A string method that checks if all letters in a string are uppercase, ignoring non-letter characters.
Example: RomanNumerals.py
A Python script example demonstrating the use of if, elif, and else clauses.
Example: Siblings.py
A Python script example that likely demonstrates string methods or random number generation.