|
| 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 | +*/ |
0 commit comments