my_list = [1, 5, 2, 8]
def sum_list(items):
total = 0 # 1. This line runs 1 time
for item in items: # 2. This loop runs 'n' timesThis task focuses on creating a function with default parameters and handling a potential error using try...except.
- Define a function named
safe_divide. - This function should accept two parameters:
numeratoranddenominator. - Give the
denominatora default parameter value of1. - Inside the function, use a
try...exceptblock. - In the
tryblock, calculate the result ofnumerator / denominatorand return it. - In the
exceptblock, catch theZeroDivisionError(the error Python gives when you divide by 0).
-
git reset --soft- Effect on Commit History: Moves the HEAD (the current branch) to the specified commit without changing the working directory or the staging area.
- Staging Area: All changes between the current commit and the target commit remain staged.
- Working Directory: Files in your working directory remain unchanged.
- Use Case: Use this when you want to undo a commit but keep the changes staged for a new commit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //---First class functions | |
| //1. Store in a variable | |
| let greet = function () { | |
| console.log('Hello'); | |
| }; | |
| // greet(); | |
| //2.Store in an object | |
| const object = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Creating the two tables | |
| CREATE TABLE Customers ( | |
| customer_id INT PRIMARY KEY, | |
| first_name VARCHAR(50), | |
| last_name VARCHAR(50), | |
| age INT, | |
| country VARCHAR(50) | |
| ); | |
| CREATE TABLE Orders ( |