Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools



Download 2,02 Mb.
Pdf ko'rish
bet102/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   98   99   100   101   102   103   104   105   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Exiting a Loop
Well, Python allows us to use the break statement to direct the flow of our
program. For instance, let us look at a program, which asks the user about
the country they have visited in their life. In our previous program, we can
use  the  “break”  statement  to  halt  the  program  once  the  user  enters  ‘quit.’
Let see how that works.
request = “\nPlease enter the country you have visited recently:”
request += “\nIf you want to exit, Enter ‘quit’ to terminate the program!”
while True
country = input(request)
if country == ‘quit’ :
break
else:
print(f “ I have visited {country.title()}.”)
The  loop  begins  with  the  “while  True”  statement,  which  runs  continually
pending when it reaches the break statement. The loop will continue to ask
the  user  to  input  the  country  they  have  visited  pending  when  they  enter
“quit.”  The  break  statement  takes  effect  when  the  user  enters  “quit”  and
causes the program to exit the loop. Our output will be as followed if the
user entered Canada, Hungry, and Portugal.
Please enter the country you have visited recently:
If you want to exit, Enter ‘quit’ to terminate the program!
I have visited Canada.
Please enter the country you have visited recently:
If you want to exit, Enter ‘quit’ to terminate the program!


I have visited Hungry.
Please enter the country you have visited recently:
If you want to exit, Enter ‘quit’ to terminate the program!
I have visited Portugal.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   98   99   100   101   102   103   104   105   ...   126




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