From d9c68df19421c60f26e0abb8f484c35c7887ccc1 Mon Sep 17 00:00:00 2001 From: jxwatson251 Date: Wed, 12 Mar 2025 20:16:40 +0000 Subject: [PATCH 1/4] Lesson_04 --- lesson_03/quiz/tsconfig.json | 2 +- lesson_04/JasonWatson/README.md | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lesson_04/JasonWatson/README.md diff --git a/lesson_03/quiz/tsconfig.json b/lesson_03/quiz/tsconfig.json index ced0628a9..d8cd088e5 100644 --- a/lesson_03/quiz/tsconfig.json +++ b/lesson_03/quiz/tsconfig.json @@ -1,4 +1,4 @@ -{ +{ "compilerOptions": { /* Visit https://aka.ms/tsconfig to read more about this file */ diff --git a/lesson_04/JasonWatson/README.md b/lesson_04/JasonWatson/README.md new file mode 100644 index 000000000..0e0a3b4b2 --- /dev/null +++ b/lesson_04/JasonWatson/README.md @@ -0,0 +1,40 @@ +## Python implementation + +```python +def is_even(number): + return number % 2 == 0 + +# Example usage: +print(is_even(4)) # Output: True +print(is_even(7)) # Output: False +``` + +## JavaScript implementation + +```javascript +function isEven(number) { + return number % 2 === 0; +} + +// Example usage: +console.log(isEven(4)); // Output: true +console.log(isEven(7)); // Output: false +``` + +## Explanation + +The Python implementation uses a function named `is_even` that takes a single argument `number`. It returns `True` if the number is even (i.e., when the remainder of the division of the number by 2 is zero), otherwise, it returns `False`. + +The JavaScript implementation uses a function named `isEven` that also takes a single argument `number`. It returns `true` if the number is even (using the same logic as the Python function) and `false` otherwise. + +### Differences + +1. **Syntax**: + - In Python, functions are defined using the `def` keyword, whereas in JavaScript, the `function` keyword is used. + - Python uses `True` and `False` for boolean values, while JavaScript uses `true` and `false`. + +2. **Type Coercion**: + - JavaScript has type coercion, which can sometimes lead to unexpected results if the input is not properly handled. In contrast, Python is more strict with types. + +3. **Function Calls**: + - The syntax for calling functions and printing to the console/output is slightly different. Python uses `print()`, while JavaScript uses `console.log()`. From 812161213fec2aab8e87151933d1070ee015d443 Mon Sep 17 00:00:00 2001 From: jxwatson251 Date: Wed, 12 Mar 2025 20:22:01 +0000 Subject: [PATCH 2/4] Lesson_04 --- lesson_04/JasonWatson/README.md | 63 ++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/lesson_04/JasonWatson/README.md b/lesson_04/JasonWatson/README.md index 0e0a3b4b2..fd3e1cd44 100644 --- a/lesson_04/JasonWatson/README.md +++ b/lesson_04/JasonWatson/README.md @@ -1,40 +1,55 @@ -## Python implementation - -```python -def is_even(number): - return number % 2 == 0 +## C + +```c +#include +#include + +bool isPrime(int n) { + if (n <= 1) return false; + for (int i = 2; i <= sqrt(n); i++) { + if (n % i == 0) return false; + } + return true; +} -# Example usage: -print(is_even(4)) # Output: True -print(is_even(7)) # Output: False +nt main() { + int number = 29; + if (isPrime(number)) + printf("%d is a prime number . \n", ) + return 0; +} ``` -## JavaScript implementation +## C++ -```javascript -function isEven(number) { - return number % 2 === 0; +```Cpp +#include +#include + +bool isPrime(int n) { + if (n <= 1) return false; + for (int i = 2; i <= sqrt(n); i++) { + if (n % i == 0) return false; + } + return true; } -// Example usage: -console.log(isEven(4)); // Output: true -console.log(isEven(7)); // Output: false +int main() { + int number = 29; + std::cout << std::boolalpha << +isPrime(number) << std::end1; + return 0; +} ``` ## Explanation -The Python implementation uses a function named `is_even` that takes a single argument `number`. It returns `True` if the number is even (i.e., when the remainder of the division of the number by 2 is zero), otherwise, it returns `False`. -The JavaScript implementation uses a function named `isEven` that also takes a single argument `number`. It returns `true` if the number is even (using the same logic as the Python function) and `false` otherwise. ### Differences -1. **Syntax**: - - In Python, functions are defined using the `def` keyword, whereas in JavaScript, the `function` keyword is used. - - Python uses `True` and `False` for boolean values, while JavaScript uses `true` and `false`. +1. ** -2. **Type Coercion**: - - JavaScript has type coercion, which can sometimes lead to unexpected results if the input is not properly handled. In contrast, Python is more strict with types. +2. ** -3. **Function Calls**: - - The syntax for calling functions and printing to the console/output is slightly different. Python uses `print()`, while JavaScript uses `console.log()`. +3. ** From 887d264829692a105218eaabb0a4e075c36ae59d Mon Sep 17 00:00:00 2001 From: jxwatson251 Date: Thu, 13 Mar 2025 14:24:25 +0000 Subject: [PATCH 3/4] Feat: Jason lesson_04 ReadMe --- lesson_04/JasonWatson/README.md | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/lesson_04/JasonWatson/README.md b/lesson_04/JasonWatson/README.md index fd3e1cd44..ac54e2bb2 100644 --- a/lesson_04/JasonWatson/README.md +++ b/lesson_04/JasonWatson/README.md @@ -1,21 +1,23 @@ ## C -```c +```C #include #include bool isPrime(int n) { if (n <= 1) return false; - for (int i = 2; i <= sqrt(n); i++) { + for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } -nt main() { +int main() { int number = 29; if (isPrime(number)) - printf("%d is a prime number . \n", ) + printf("%d is a prime number . \n", number ); + else + printf("%d is not a prime number . \n", number ); return 0; } ``` @@ -43,13 +45,26 @@ isPrime(number) << std::end1; ``` ## Explanation +This C program checks if a given nember is a prime number.It uses a function isPrime() to then determine whether a number is a prime number and the gives the output. + +This C++ program checks when a given number is a prime number by using the simple function isPrime() and the gives an out. It does so by using the which is a library for input/output and the for calculation. + + +### DIFFERENCES + +1. **Syntax**: + - In C it uses a standard input-output library which gives us the ability to use functions such as print() to give output. + - In C++ it uses a standard input-output stream library which makes us be able to use std::cout and std::endl to display the output. + +2. **How they carry out calculation**: + - C uses the bool data type to which provides true and false values for logical operation whilst the C++ use a math library to do mathematical functions such as sqrt() that calculkates square root numbers. -### Differences +### SIMILARITIES -1. ** +1. **Codes**: + - Both C and C++ use the function if (n <= 1) return false to determine if the number is a prime number. + - They both have the ability to do loop for Checking Divisibility. + - the function return true; is use by both programs to return true if No Divisors found. -2. ** - -3. ** From f39ffcc21909907441d5e2e5aaeef268b600175c Mon Sep 17 00:00:00 2001 From: "Anthony D. Mays" Date: Thu, 20 Mar 2025 21:05:32 +0000 Subject: [PATCH 4/4] chore: revert lesson_03 changes Signed-off-by: Anthony D. Mays --- lesson_03/quiz/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesson_03/quiz/tsconfig.json b/lesson_03/quiz/tsconfig.json index d8cd088e5..ced0628a9 100644 --- a/lesson_03/quiz/tsconfig.json +++ b/lesson_03/quiz/tsconfig.json @@ -1,4 +1,4 @@ -{ +{ "compilerOptions": { /* Visit https://aka.ms/tsconfig to read more about this file */