-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFor_Loop.py
More file actions
133 lines (122 loc) · 2.79 KB
/
Copy pathFor_Loop.py
File metadata and controls
133 lines (122 loc) · 2.79 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
""" _______________________________ """
#!""" FOR LOOP """
""" print all letters (String) """
print("The string length is: ",len('Hope'))
for letter in "Hope":
print(letter)
""" #* The output is
The buddies length is: 4
H
o
p
e
"""
""" print all element (Array) """
buddies = ["pikachu","grandizer","subzero"]
print("The buddies length is: ",len(buddies))
for buddy in buddies:
print(buddy)
""" #* The output is
The buddies length is: 3
pikachu
grandizer
subzero
"""
""" print all number between 0 to (5-1 = 4) """
for x in range(5):
print(x)
""" #* The output is
0
1
2
3
4
"""
""" print all number between 7 to (11-1 = 10) """
for y in range(7,11):
print(y)
""" #* The output is
7
8
9
10
"""
""" print the index number then print the value """
new_list = ["Hope","Amal","Akira","Yuki"]
for index in range(len(new_list)):
print(index)
""" #* The output is
0
1
2
3
"""
for i in range(len(new_list)):
print(new_list[i])
""" #* The output is
Hope
Amal
Akira
Yuki
"""
""" Check if the number even or odd for all numbers between 0 to (10-1=9) """
for n in range(10):
if n % 2 ==0:
print(n," is an even number")
else:
print(n," is an odd number")
""" #* The output is
0 is an even number
1 is an odd number
2 is an even number
3 is an odd number
4 is an even number
5 is an odd number
6 is an even number
7 is an odd number
8 is an even number
9 is an odd number
"""
""" Check if this value equal "Winner" when it match finish the loop """
my_arr = ["False","True","Winner","Lost"]
for value in range(len(my_arr)):
if my_arr[value] == "Winner":
print(value," is the Winner")
break
else:
print(value," is not the Winner")
""" #* The output is
0 is not the Winner
1 is not the Winner
2 is the Winner
"""
""" Check if "Akira" is your friend --> (found in array) """
for val in new_list:
if val == "Akira":
print(val," is your friend! :)")
break
else: print("NOT FOUND")
""" #* The output is
Akira is your friend! :)
"""
""" All number between 3 to 9 are chosen number except 5 (Because we have continue when x=5) """
for x in range(3,10):
if x == 5:
continue
print(x, " is the chosen number")
""" #* The output is
3 is the chosen number
4 is the chosen number
6 is the chosen number
7 is the chosen number
8 is the chosen number
9 is the chosen number
"""
""" Power Function """
def POWER(base_num,pow_num):
result = 1
for index in range(pow_num):
result = result * base_num
return result
print(POWER(2,5)) #* The output is 32
""" _______________________________ """