-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Required concepts: https://www.w3schools.com/python/python_intro.asp map, filter, lambda | ||
|
||
print('Question: prime numbers in list,') | ||
|
||
def check_prime(num): | ||
# note: you can end the for loop at √num | ||
for i in range(2,num): | ||
if num == 1: | ||
return False | ||
if num%i == 0: | ||
# you found a factor of num! | ||
return False | ||
# you didn't find any multiple, you're prime | ||
return True | ||
|
||
li = [2,3,4,5,6,7,8,9] | ||
print(li) | ||
|
||
primes = filter(check_prime,li) | ||
|
||
print(list(primes)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
# Required concepts: https://www.w3schools.com/python/python_intro.asp while loop and maths | ||
print('Question: reverse number without using strings') | ||
|
||
def getReverse(num): | ||
res = 0 | ||
while num > 0: | ||
# take last digit and put in the front of res | ||
digit = num%10 | ||
num //=10 | ||
res = res*10 + digit | ||
return res | ||
print(getReverse(1234)) | ||
# Required concepts: https://www.w3schools.com/python/python_intro.asp map, filter, lambda | ||
|
||
print('Question: prime numbers in list,') | ||
|
||
def check_prime(num): | ||
for i in range(2,num): | ||
if num == 1: | ||
return False | ||
if num%i == 0: | ||
# you found a factor of num! | ||
return False | ||
# you didn't find any multiple, you're prime | ||
return True | ||
|
||
li = [2,3,4,5,6,7,8,9] | ||
print(li) | ||
|
||
primes = filter(check_prime,li) | ||
|
||
print(list(primes)) |