Skip to content

Commit 54cd199

Browse files
authored
Merge branch 'code-differently:main' into main
2 parents a3b9984 + 72eb5bf commit 54cd199

File tree

6 files changed

+187
-0
lines changed

6 files changed

+187
-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))

lesson_04/cdbluejr/Prime.bas

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
100 rem find prime number
2+
110 n =1
3+
120 c=0
4+
130 i=1
5+
140 if i<=n or (n mod i)<>0 then 300
6+
145 if i=n and c=2 then 200
7+
150 c=c+1
8+
160 if i>n then 210
9+
170 goto 130
10+
11+
200 Print n + “Prime"
12+
210 c=0
13+
220 n=n+1
14+
230 if c>n then 120
15+
240 goto 130
16+
17+
300 i=i+1
18+
310 goto 140

lesson_04/cdbluejr/Prime.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Prime {
2+
public static void main(String[] args) {
3+
4+
5+
int num = 29;
6+
int count = 0;
7+
for(int i=1; i<=num; i++) {
8+
if(num % i ==0) {
9+
count++;
10+
}
11+
}
12+
if(count==2) {
13+
System.out.println("Prime");
14+
} else {
15+
System.out.println("not Prime");
16+
}
17+
}
18+
}
19+

lesson_04/cdbluejr/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Java implementation
2+
3+
int num = 29;
4+
int count = 0;
5+
for(int i=1; i<=num; i++) {
6+
if(num % i ==0) {
7+
count++;
8+
}
9+
}
10+
if(count==2) {
11+
System.out.println("Prime");
12+
} else {
13+
System.out.println("not Prime");
14+
15+
16+
## Basic implementation
17+
18+
100 rem find prime number
19+
110 n =1
20+
120 c=0
21+
130 i=1
22+
140 if i<=n or (n mod i)<>0 then 300
23+
145 if i=n and c=2 then 200
24+
150 c=c+1
25+
160 if i>n then 210
26+
170 goto 130
27+
28+
200 Print n + “Prime"
29+
210 c=0
30+
220 n=n+1
31+
230 if c>n then 120
32+
240 goto 130
33+
34+
300 i=i+1
35+
310 goto 140
36+
37+
## Explanation
38+
39+
The java implementation uses the counting system to only count to 2, to signify a prime number.
40+
41+
The basic implementation also uses the counting system to only count to 2, to signify a prime number.
42+
43+
### Differences
44+
45+
1. **Syntax**:
46+
- In Java, it uses the fuctions Modelo function to determine if the reminder is zero to determine if the number is divisable evenly.
47+
- Basic uses the if then else function to determine if the number is prime or not.
48+
49+
3. **Function Calls**:
50+
- The ability to print for both programs are different, java uses System.out.println, while BASIC just uses the word print.
51+

0 commit comments

Comments
 (0)