Skip to content

Commit 72eb5bf

Browse files
authored
feat: adds Angelica's code samples (#151)
* finished code * lesson done with two languages
1 parent 8887641 commit 72eb5bf

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

lesson_04/AngelicaC/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
```python
2+
# takes input from console and sets it to integer
3+
number = int(input(Enter the number: "))
4+
#when no number input=false
5+
flag = false
6+
##check to see if numbers divide by 2,if true it breaks function.
7+
for i in range (2, number):
8+
if (number % i ==0):
9+
flag = true
10+
break
11+
##entered number is not prime and will return it
12+
if flag:
13+
print("Entered number {} is not a prime number".format(number))
14+
##entered number is a prime number
15+
else:
16+
print("Entered number {} is a prime number".format(number))
17+
```
18+
number = int(input("Enter a whole number: "))
19+
20+
21+
```javascript
22+
// the function will be calling an n that it will output.
23+
function isprime(n) {
24+
// if the output n is 1, it will be false
25+
if (n <=1)
26+
return false;
27+
// i will be a number that will loop from 2 to the square root of n.
28+
for (let i = 2; i < n;i++) {
29+
if(n % i ===0) {
30+
return false;
31+
}
32+
}
33+
return true;
34+
35+
}
36+
37+
console.log(isprime(5))
38+
39+
## Explanation
40+
41+
/*Python function uses the i as variable if. If the variable gets divided by 2 and it results in 0, then it is true and the code will not run/break.
42+
*/
43+
44+
/* In javaScript the function will be calling an n that it will output. if the output n is 1, it will be false. i will be a number that will loop from 2 to the square root of n.
45+
*/
46+
47+
/*Differences
48+
when using python, the language will use `if` keyword, to deteremine if the number will be an interger. Whereas, in Javascript, the language being used will be called a `function`.
49+
*/
50+
51+
/*Type coercion
52+
Python is particular when it comes to the input the variable and can have different outputs.
53+
Javascript is easier to write but if it not input correctly,it can affect the code.
54+
*/
55+
56+
/*Function calls
57+
Syntax to call the fucntion for python is
58+
number = int().
59+
Syntax for Javascript is console.log().
60+
*/
61+
62+
/*Citations
63+
Python
64+
https://www.youtube.com/watch?v=J-5swSZj_iI
65+
66+
Javascript
67+
https://www.youtube.com/watch?v=cmco9fi3xnA
68+
*/

lesson_04/AngelicaC/python.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
number = int(input("Enter the number:"))
2+
#
3+
flag = False
4+
5+
if (number <= 1):
6+
flag = False
7+
8+
for i in range (2, number):
9+
if (number % i ==0):
10+
flag = True
11+
break
12+
13+
if flag:
14+
print("Entered number {} is not a prime number".format(number))
15+
else:
16+
print("Entered number {} is a prime number".format(number))

lesson_04/AngelicaC/script.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function isprime(n) {
2+
// if the output n is 2, it will be false
3+
if (n <2)
4+
return false;
5+
// i will be a number that will loop from 2 to the square root of n.
6+
for (let i = 2; i <= Math.sqrt(n);i++) {
7+
if(n % i ===0) {
8+
return false;
9+
}
10+
}
11+
return true;
12+
13+
}
14+
15+
console.log(isprime(5))

0 commit comments

Comments
 (0)