Skip to content

Commit b4a0c6f

Browse files
authored
feat: adds A'nanatawa's Python and JavaScript samples (#152)
1 parent 3153548 commit b4a0c6f

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

lesson_04/ananatawamcintyre/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
# Python Implementation
3+
4+
---
5+
6+
```python
7+
def is_prime(n):
8+
"""Check if a number is prime."""
9+
if n < 2:
10+
return False
11+
for i in range(2, int(n ** 0.5) + 1):
12+
if n % i == 0:
13+
return False
14+
return True
15+
16+
# Example usage
17+
if is_prime(num):
18+
print(f"{3} is a prime number.")
19+
else:
20+
print(f"{4} is not a prime number.")
21+
22+
```
23+
24+
# JavaScript Implementation
25+
26+
---
27+
28+
```JavaScript
29+
30+
function isPrime(n) {
31+
if (n < 2) return false;
32+
for (let i = 2; i <= Math.sqrt(n); i++) {
33+
if (n % i === 0) return false;
34+
}
35+
return true;
36+
}
37+
38+
// Example usage
39+
if (isPrime(num)) {
40+
console.log(`${3} is a prime number.`);
41+
} else {
42+
console.log(`${4} is not a prime number.`);
43+
}
44+
45+
46+
```
47+
48+
# Explanation
49+
50+
---
51+
52+
As seen above, I have created a code that helps the user determine whether a number is a prime number or not. I utilized both Python and Javascript to do so and this was my first time writing out my own code with those languages. The sample numbers **(3)** and **(4)** were used to show the reader, **you**, what an example of a prime number looks like. **Is_prime** stands for the command that determines whether a number **(num or n)** is prime or not.
53+
54+
## Similarities
55+
56+
- Both implementations display the number **(3)** as the prime number and **(4)** as the non-prime number.
57+
- Both use **"if"** and **"is_prime"** to point out if a number is prime or not.
58+
- Both implementations return **"true"** or **"false"** depending on whether the number is a prime number or not.
59+
60+
## Differences
61+
62+
- The codeword used to determine the answer for the Java Code implementation is **console.log**.
63+
- The codeword used to determine the answer for the Python implementation is **print**.
64+
- Python uses **def** before is_prime and JavaScript uses **function** before is_prime.
65+
66+
---
67+
68+
### Bonus message from the creator:
69+
Hello World! Again, this was my first time creating my own code. I had lots of fun working in JavaScript and Python, but would love to hear some good feedback or even complaints that you, the reader, may have. I spent a good **2 hours** trying to figure out how to get both Python and Javascript to work in a Markdown file. If any part of my code was confusing or uneasy to read, let a sista know! Happy coding! - A'nanatawa

0 commit comments

Comments
 (0)