mirror of
https://github.com/ossu/computer-science.git
synced 2025-08-11 07:40:15 -04:00
add counting and filtered-count patterns in 1.1.3
This commit is contained in:
parent
89baff3f40
commit
62b7aa9967
2 changed files with 22 additions and 0 deletions
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…
Add table
Add a link
Reference in a new issue