-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09_Loops_For.py
More file actions
85 lines (54 loc) · 1.38 KB
/
09_Loops_For.py
File metadata and controls
85 lines (54 loc) · 1.38 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
##Loops:Loops in Python are used to repeat actions efficiently. The main types are For loops (counting through items) and While loops (based on conditions).
##Life is Loop
##For loop: provides the ability to loop over the items of any sequence
##For Loop
numbers = (34,54,67,21,7)
total = 0
for num in numbers:
total += num
print ("Total =", total)
elementList=('a', "Python", 35,True, 0,-9)
for i in elementList:
print(i)
##For loop with List, Tuple, String and Dictionary
nameList= ["Ronaldo", "Messi", "Mabape", "Ramos"]
for name in nameList:
print(name)
print()
nameTuple=("Dhoni","Pointing","Sachin","Breet Lee","Dravid")
for name in nameTuple:
print(name)
print()
nameString="Cristiano Ronaldo"
for name in nameString:
print(name)
print()
nameDict=dict ({'a':0,'b':945, 'c':46})
for name in nameDict:
print(name, nameDict[name])
print()
##For loop with else
nameList= ["Ronaldo", "Messi", "Mabape", "Ramos"]
for name in nameList:
print(name)
else:
print("Inside the else Block")
print()
##Q1. WAP to print namne without Owels
name="John Doe"
for char in name:
if char not in 'aeiou':
print(char, end='')
##For loop with Range
##range(stop)
for i in range(10):
print(i, end=' ')
print()
##range(start, stop)
for i in range(3,10):
print(i, end=' ')
print()
##range(start, stop, step)
for i in range(1,10,3):
print(i, end=' ')
print()