Skip to content

Updated Lesson 04 #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
74bc872
Create chelseaogbonnia's readme
Cogbonnia Sep 24, 2024
5b0500c
Merge branch 'code-differently:main' into patch-1
Cogbonnia Sep 26, 2024
c076b66
Update and rename lesson_00/chelseaogbonnia to lesson_00/chelsea_ogbo…
Cogbonnia Sep 26, 2024
7fa2914
Rename ReadME.md to README.md
Cogbonnia Sep 26, 2024
42367e3
Merge branch 'code-differently:main' into patch-1
Cogbonnia Sep 27, 2024
f462dc4
Merge branch 'code-differently:main' into patch-1
Cogbonnia Sep 29, 2024
0c1b121
Merge pull request #1 from Cogbonnia/patch-1
Cogbonnia Sep 29, 2024
fb73c3d
Create style.css
Cogbonnia Sep 30, 2024
f7fdc12
Created index.html
Cogbonnia Sep 30, 2024
e85d1e7
Commit Message: Testing
Cogbonnia Sep 30, 2024
6bb03b6
Merge branch 'code-differently:main' into main
Cogbonnia Sep 30, 2024
edd4935
Merge pull request #3 from Cogbonnia/patch-1_lesson02
Cogbonnia Sep 30, 2024
db53d2c
Merge branch 'code-differently:main' into patch-1
Cogbonnia Sep 30, 2024
f5387e0
Merge remote-tracking branch 'origin/patch-1'
Cogbonnia Sep 30, 2024
c3af986
Merge branch 'code-differently:main' into main
Cogbonnia Sep 30, 2024
975512f
Merge branch 'code-differently:main' into main
Cogbonnia Sep 30, 2024
05f4fb9
Merge branch 'code-differently:main' into main
Cogbonnia Oct 1, 2024
a571ff7
Merge branch 'code-differently:main' into main
Cogbonnia Oct 1, 2024
0df64a5
Merge branch 'code-differently:main' into main
Cogbonnia Oct 1, 2024
dbd1fbf
chore: remove invalid files
anthonydmays Oct 2, 2024
8d17ea7
Delete lesson_02/lib/typescript/codedifferently-instructional/package…
anthonydmays Oct 2, 2024
6fc8c88
Merge branch 'code-differently:main' into main
Cogbonnia Oct 2, 2024
a496bc2
Merge branch 'code-differently:main' into main
Cogbonnia Oct 2, 2024
1b3c1d5
Merge branch 'code-differently:main' into main
Cogbonnia Oct 2, 2024
2b9355e
Created my quiz and added my answers.
Cogbonnia Oct 2, 2024
d75a5a0
Update lesson2.ts
Cogbonnia Oct 2, 2024
5d06788
Merge pull request #4 from Cogbonnia/Lesson_02
Cogbonnia Oct 2, 2024
5d549f2
Merge branch 'main' into main
Cogbonnia Oct 2, 2024
7b2183c
Create README.md
Cogbonnia Oct 2, 2024
7a5d3ea
Merge branch 'code-differently:main' into Lesson_04
Cogbonnia Oct 3, 2024
3862a87
Update README.md
Cogbonnia Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lesson_02/quiz/src/lesson2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Lesson2 {
[AnswerChoice.C, "To delete unnecessary files"],
[AnswerChoice.D, "To run code more efficiently"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.B, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -56,7 +56,7 @@ export class Lesson2 {
[AnswerChoice.C, "A tool for merging branches"],
[AnswerChoice.D, "A way to delete a repository"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.A, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -70,7 +70,7 @@ export class Lesson2 {
[AnswerChoice.C, "Push changes to the server"],
[AnswerChoice.D, "Write code directly in GitHub"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.D, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -84,7 +84,7 @@ export class Lesson2 {
[AnswerChoice.C, "git branch"],
[AnswerChoice.D, "git pull"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.B, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -98,7 +98,7 @@ export class Lesson2 {
[AnswerChoice.C, "NetBeans"],
[AnswerChoice.D, "VS Code"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.D, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -112,7 +112,7 @@ export class Lesson2 {
[AnswerChoice.C, "Dev Containers"],
[AnswerChoice.D, "Source Control"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.C, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -126,7 +126,7 @@ export class Lesson2 {
[AnswerChoice.C, "Playing music"],
[AnswerChoice.D, "Managing source control"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.C, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -140,7 +140,7 @@ export class Lesson2 {
[AnswerChoice.C, "cd"],
[AnswerChoice.D, "mkdir"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.B, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -154,7 +154,7 @@ export class Lesson2 {
[AnswerChoice.C, "cd"],
[AnswerChoice.D, "mkdir"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.C, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -168,7 +168,7 @@ export class Lesson2 {
[AnswerChoice.C, "Remove a file or directory"],
[AnswerChoice.D, "Copy a file or directory"],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.A, // Replace `UNANSWERED` with the correct answer.
);
}

Expand All @@ -182,7 +182,7 @@ export class Lesson2 {
[AnswerChoice.C, "⌘ + Q"],
[AnswerChoice.D, '⌘ + S, then type "terminal"'],
]),
AnswerChoice.UNANSWERED, // Replace `UNANSWERED` with the correct answer.
AnswerChoice.B, // Replace `UNANSWERED` with the correct answer.
);
}
}
Expand Down
77 changes: 77 additions & 0 deletions lesson_04/chelseaogbonnia/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Prime Number Finder (Python and JavaScript) #

This project demonstrates how to find prime numbers between 1 and 100 using two programming languages: Python and JavaScript. Each function uses a for loop to check whether a number is prime, and both include inline comments to explain the code step by step. Additionally, there are detailed explanations after each function.

## Prime Number Finder in Python ##
```
# Function to find prime numbers between 1 and 100 in Python
def find_prime_num_py():

# Loop through numbers from 2 to 100
for num in range(2, 101):
is_prime = True # Assume the number is prime

# Check if num is divisible by any number between 2 and its square root
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False # If divisible, not a prime number
break # Exit the loop early

# If is_prime is still true, num is a prime number
if is_prime:
print(num) # Output the prime number

# Call the Python function
find_prime_num_py()
```
### Python Explanation: ###
The Python function, find_prime_num_py, uses a for loop to iterate through the numbers between 2 and 100. The is_prime variable is set to True for each number. Inside the inner loop, we check if the number is divisible by any integer between 2 and the square root of the number. If the number is divisible, it is marked as not prime, and we break out of the inner loop to stop further unnecessary checks. The square root limit ensures better performance. When the number is confirmed to be prime, it is printed to the console.


## Prime Number Finder in JavaScript ##
```
// Function to find prime numbers between 1 and 100 in JavaScript
function findPrimeNumberJS() {

// Loop through numbers from 2 to 100
for (let num = 2; num <= 100; num++) {
let isPrime = true; // Assume the number is prime

// Check if num is divisible by any number between 2 and its square root
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) {
isPrime = false; // If divisible, not a prime number
break; // Exit the loop early
}
}

// If isPrime is still true, num is a prime number
if (isPrime) {
console.log(num); // Output the prime number
}
}
}

// Call the JavaScript function
findPrimeNumberJS();
```

### JavaScript Explanation: ###
In this JavaScript function, findPrimeNumberJS, we use a for loop to iterate over the numbers from 2 to 100. The isPrime variable initially assumes that each number is prime. For each number num, we check if it is divisible by any number from 2 to the square root of num. If the number is divisible, it is marked as not prime by setting isPrime to false, and we break out of the inner loop to save time. If the number remains prime after the check, it is printed to the console. The square root check ensures we minimize the number of iterations for efficiency.

## Similarities and Differences Between Python and JavaScript Prime Number Functions ##

### Similarities

* Logic (Using Square Roots to Check Primes): Both functions in Python and JavaScript use the same fundamental logic to determine if a number is prime. By checking divisors only up to the square root of the number, we can efficiently reduce the number of checks. This optimization works in both languages because if a number has a divisor greater than its square root, it must also have a corresponding smaller divisor, which would have been checked already.

* Looping Structure: Both functions use a for loop to iterate over potential divisors, starting from 2. While the exact syntax differs, the purpose is the same—to test whether the number is divisible by any number within this range. If no divisor is found, the number is prime.


### Differences:

* Syntax: Python uses range() to generate numbers in a loop, while JavaScript directly declares the loop variable and sets its conditions. Python also uses indentation to define code blocks, while JavaScript uses curly braces {}.

* Case Sensitivity: Python commonly uses snake_case for function and variable names (e.g., is_prime), while JavaScript typically uses camelCase (e.g., isPrime).

* Variable Declarations: In Python, variables are declared by simply assigning a value to them (e.g., num = 5). In JavaScript, variables must be explicitly declared using let, const, or var (e.g., let num = 5).