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



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

Code Blocks and Indentation


In most other programming languages, indentation is used only to help make the code look pretty. For Python though, it is required for indicating a block of code. Let’s take our previous code from the “Handling Errors” section. The two lines after our try statement are indented and are known as blocks of code. These lines belong to the try statement because they are directly indented after the statement. The same goes for our other print statement within the except block. It’s the reason that our nonvalid print statement only runs if the except block runs. All blocks of code need to be connected to a statement; you can’t indent a section randomly.
Note The indents must be consistent. It does not always need to be four spaces; however, a tab is four spaces, so it's usually easier to indent with tabs.

MONDAY EXERCISES


  1. Converting: Try converting a string of “True” to a boolean, and then output its type to make sure it converted properly.

  2. Sum of Inputs: Create two input statements, and ask the user to enter two numbers. print the sum of these numbers out.

  3. Car Information: Ask the user to input the year, make, model, and color of their car, and print a nicely formatted statement like “2018 Blue Chevrolet silverado.”


Today was an important step in covering user input, how to convert from one data type to another, and how to handle errors.
Tuesday: If Statements
Today we’ll learn all about how to make decisions in our code. This will give us the ability to have our programs decide what lines of code to run, depending on what the user inputs, calculations, etc. This is the most important lesson of this week. Be sure to spend a good amount of time going on today’s lesson.
To follow along with this lesson, let’s continue from our previous notebook file
Week_03” and simply add a markdown cell at the bottom that says, “If Statements.

Download 2,61 Mb.

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