Skip to content

Commit 81709aa

Browse files
committed
Me doing some challenge practices with writing a method and for loop iterating through an element.
1 parent 3b2cdac commit 81709aa

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

practice.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,27 @@ def sayHello(name="User"):
4949
print(item)
5050
print("-"*20)
5151

52-
52+
# Create a list of items (you may use either strings or numbers in the list),
53+
# then create an iterator using the iter() function.
54+
#
55+
# Use a for loop to loop "n" times, where n is the number of items in your list.
56+
# Each time round the loop, use next() on your list to print the next item.
57+
#
58+
# hint: use the len() function rather than counting the number of items in the list.
59+
60+
def looper(el):
61+
times = len(el)
62+
myIter = iter(el)
63+
while times >= 1:
64+
print(next(myIter))
65+
times -= 1
66+
67+
# looper("1234567890")
68+
# print("*"*20)
69+
# looper([1,2,3,4,5,6,7,8,9,0])
70+
71+
element = [1,2,3,4,5,6,7,8,9,0]
72+
times = len(element)
73+
myIter = iter(element)
74+
for item in range(times):
75+
print(next(myIter))

0 commit comments

Comments
 (0)