mirror of
https://github.com/ossu/computer-science.git
synced 2025-01-30 00:03:41 -05:00
add counting and filtered-count patterns in 1.1.3
This commit is contained in:
parent
89baff3f40
commit
62b7aa9967
Binary file not shown.
@ -1 +1,23 @@
|
|||||||
# Loops - http://beastie.cs.ua.edu/cs150/book/index_14.html
|
# Loops - http://beastie.cs.ua.edu/cs150/book/index_14.html
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while i < 5:
|
||||||
|
print i
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
# Other loops
|
||||||
|
for i in range(0, 5, 1): # 5 exclusive
|
||||||
|
print i
|
||||||
|
|
||||||
|
# The counting pattern
|
||||||
|
count = 0
|
||||||
|
for i in range(0, len(items), 1):
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
# The filtered-count pattern
|
||||||
|
count = 0
|
||||||
|
for i in range(0, len(items), 1):
|
||||||
|
if items[i] % 2 == 0:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user