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



Download 2,61 Mb.
bet45/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   41   42   43   44   45   46   47   48   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

How They Work


Every day you make hundreds of decisions. These decisions define what you do with your day. In programming these are known as branching statements or “if statements.” An if statement works the same way that a decision is made. You check a condition, and if that condition is true, you perform the task, and if it’s not true, then you move on without performing that task:
Am I hungry?”
Yes, so I should make some food.”
*** proceeds to cook food ***
The same decision-making process can be implemented in programming using an if statement.

Writing Your First If Statement


All branching statements begin the same way, with the keyword “if”. Following the keyword is what is known as a condition. Lastly, there will always be an ending colon at the end of the statement. The if statement checks to see if the given condition is True or False. If the condition is True, then the code block runs. If it is False, then the program continues without running any of the code indented directly after the if statement. Let’s try it out:

# using an if statement to only run code if the condition is met x, y = 5, 10 if x < y: print("x is less than y")

Go ahead and run that cell. Notice here that the output is “x is less than y”. This is because we originally declared x equal to 5 and y equal to 10 and then used an if statement to check if x was less than y, which it was. If x was equal to 15, then the print statement indented after the “if” would have never ran, because the condition would have been False.
ChApTer 3 User InpUT And CondITIonAls

Comparison Operators


Before we continue with branching statements, we need to go over comparison operators. So far, we’ve used arithmetic operators for adding and subtracting values and assignment operators for declaring variables, and with the introduction of the “if statement,” we’ve now seen comparison operators. There are several comparisons that you’re able to make. Most comparison operators that you’ll use, however, are shown in Table 3-2.
Table 3-2. Comparison operators


Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   41   42   43   44   45   46   47   48   ...   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