-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlooping.py
More file actions
48 lines (39 loc) · 923 Bytes
/
looping.py
File metadata and controls
48 lines (39 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Looping While
def print_numbers_while(n):
i = 1
while i <= n:
print(i)
i += 1
return "Done"
# Test the function
print(print_numbers_while(5))
# Looping For
def print_numbers_for(n):
for i in range(1, n + 1):
print(i)
return "Done"
# Test the function
print(print_numbers_for(5))
# More Examples Looping Any Situation
def print_numbers_skip(n):
for i in range(1, n + 1):
if i % 2 == 0:
continue
print(i)
return "Done"
# Test the function
print(print_numbers_skip(5))
# Additional Examples Looping Any Situation
def print_numbers_reverse(n):
for i in range(n, 0, -1):
print(i)
return "Done"
# Test the function
print(print_numbers_reverse(5))
# Looping With String Dummy Data Example
def print_characters(s):
for char in s:
print(char)
return "Done"
# Test the function
print(print_characters("Hello"))