-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7 - Control Statement.py
More file actions
45 lines (37 loc) · 1004 Bytes
/
7 - Control Statement.py
File metadata and controls
45 lines (37 loc) · 1004 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
#Looping in Python:-
"""Iterable Elements:- (str,list,tuple,dict,range,set)
Syntax Format:-
for [variable_name] in [iterable Datatype]:
statements
"""
l = [10,20,30,40,50]
"""print(l)"""
for value in l:
print(value)
"""sum = 0+10 = 10
10+20 = 30
30+30 = 60
60+40 = 100
100+50 = 150
"""
sum = 0
for value in l:
sum = sum+value
print(sum)
"""In python:- there is a function called Range
range(5) = 0 1 2 3 4
range(10,100) = 10 11 12 13 14 15 ......99
range(10,100,5) = 10 15 20 25 30 35 ....90 95 100
"""
for value in range(5):
print(value)
# Here if we want to print 0 to 4 then write 5 in range because it prints from 0 to n-1 (where n= entered range)
for shubham in range(20,100):
print(shubham)
for value in range(10,100,5):
print(value)
# Here i wan tot start from 10 and print till 100 but i want difference of 5
sum = 0
for value in range(1,21):
sum = sum+value
print(sum)