Skip to content

Commit d69629f

Browse files
committed
control statemnts
1 parent 2ca0a3c commit d69629f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

ControlStatments/LoopStatements.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
11
# loop statements in Python
2+
3+
4+
#Print numbers 1 to 10
5+
6+
x = 1
7+
while x<=10:
8+
print(x)
9+
x +=1
10+
print('End of Program!')
11+
12+
13+
#For loop
14+
15+
for char in 'John':
16+
print(char) #Each character is printed
17+
18+
print()
19+
print()
20+
21+
a=range(10)
22+
for i in a:
23+
print(i) #Prints number 0-9
24+
print()
25+
26+
#Prints 10 to 1 numbers
27+
k = range(10,0,-1)
28+
for z in k:
29+
print(z)
30+
31+
print()
32+
print()
33+
#Break and continue
34+
35+
#Find first odd number in the given list
36+
list = [10,50,11,12,17]
37+
for i in list:
38+
if(i%2 == 0):
39+
continue
40+
print(i)
41+
break
42+
43+
#Result: 11
44+

DataTypes/Range.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#buil in range()
2+
#sequence generated through range function is immutable
3+
4+
a = range(10)
5+
print(a) # range(0, 10)
6+
print(type(a)) #<class 'range'>
7+
8+
print(range(0,10)) #range(0, 10)
9+
10+
print(a[5]) #5
11+
12+
print(range(0,10,2)) #range -- 0,2,4,6,8
13+

0 commit comments

Comments
 (0)