Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming



Download 2,61 Mb.
bet62/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   58   59   60   61   62   63   64   65   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Loop Iteration

Value of Num

Output

1

0

Value: 0

2

1

Value: 1

3

2

Value: 2

4

3

Value: 3

5

4

Value: 4

Note the value 5 is not output because range( ) counts up to but not including

Range( )


Range allows us to count from one number to another while being able to define where to start and end and how much we increment or decrement by. Meaning that we could count every other number or every fifth number if we wanted to. When used with a for loop, it gives us the ability to loop a certain number of times. In the previous example, we saw that a range of 5 printed out five numbers. This is because range defaults to starting at 0 and increments by 1 each time. Let’s see another example:

# providing the start, stop, and step for the range function for num in range(2, 10, 2):
print( "Value: { }".format(num) ) # will print all evens between 2 and 10

Go ahead and run that cell. This time we’ve specified our program to start the loop at the value of 2 and count to 10 but increment by 2. The output for our values becomes
2, 4, 6, 8”.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   58   59   60   61   62   63   64   65   ...   200




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish