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



Download 2,61 Mb.
bet39/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   35   36   37   38   39   40   41   42   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Displaying the Total


Like the products section, we want to create a header for our total, but we want to also center it underneath the price column of the products section. To do so, we’ll use three tabs:

36| # print out header for section of total
37| print("\t\t\tTotal")

Go ahead and run the cell. Now that we have our total header aligned with the price column in products, we can output our total on the next line. Before we can print out a total, however, we must first calculate the total, which is the sum of all our products. Let’s define a variable called total and then print it out:

39| # calculate total price and print out
40| total = p1_price + p2_price + p3_price
41| print( "\t\t\t${ }".format(total) )

Go ahead and run the cell. Again, we’ve gone ahead and added three tabs, plus a dollar sign to make the total value appear as currency. Let’s now add a section border:

43| # print a line between sections
44| print( "=" * 50)

Go ahead and run the cell to make sure it looks like the desired output so far.

Displaying the Ending Message


To display the final thank you message, our design has it spaced out slightly more than any other section, so we’ll need to add a couple of newlines to give it some extra spacing:

46| # output thank you message
47| print( "\n\t{ }\n".format(message) )

Go ahead and run the cell. Our message is now centered, and we’re ready to move on.

Displaying the Bottom Border


To finish off this simple printing program, we need to throw in a bottom border for aesthetics:

49| # create a bottom border
50| print( "*" * 50 )

Go ahead and run the cell one last time.
Congratulations! As simple as it may be, it’s a huge milestone. After learning more material, try coming back here to improve it.
Weekly Summary
This week we went over some very important foundational concepts in programming with variables and working with strings. You must always keep in mind that variables need to be declared before you can use them and that the name associated is saved in memory with the value on the right side of the equals operator. Strings are easy to work with in Python, as the language has a variety of methods that we can call in order to do the work for us. At the end of the week, we were able to build a simple receipt printing program. Try breaking the program! I always encourage students to try and break programs because it will teach you how to fix it.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   35   36   37   38   39   40   41   42   ...   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