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



Download 2,61 Mb.
bet90/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   86   87   88   89   90   91   92   93   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Handling User Input


The last step of this program is to add the functions we previously created to handle user input:

49| done = True ◽◽◽ 50| elif ans == "add":
51| item = input("What would you like to add? ").title( ) 52| addItem(item) 53| elif ans == "remove":
54| showCart( )
55| item = input("What item would you like to remove? ") .title( )
56| removeItem(item) 57| elif ans == "show":
58| showCart( ) 59| elif ans == "clear":
CHapTeR 5 FUnCTIonS
60| clearCart( ) 61| else:
62| print("Sorry that was not an option.")
64| main( ) # run the program

Go ahead and run the cell. We’ve included several elif statements to handle the user’s input. Now, depending on what they choose, we’ll be able to call the necessary function. On lines 51 and 55, we accept a second input from the user to type in the item they would like to add or remove, but we make sure to change it to title case for case sensitivity purposes. If they don’t choose a proper task to perform, we make sure that we let them know through the else clause.

Final Output


Congratulations on completing this project! Due to the size of the project, you may find the completed version of the code on Github. To find the specific code for this project, simply open or download the “Week_05.ipynb” file. If you ran into errors along the way, be sure to cross-reference your code with the code in this file and see where you may have gone wrong.
Today we were able to build out a full shopping cart program with the use of functions. We can see that our main loop is clean and easy to read. even with this small program, we can see the power of functions.
Weekly Summary
This week was a big step forward into improving our programming skills. We learned that functions are useful in reducing the number of lines of code written. They help to make our program more efficient and easier to read. They can become modular using parameters or even return specific data using the return keyword. One of the last concepts we covered was how to deal with scope in a project and how it handles a variables accessibility. At the end of the week, we built the shopping cart program together to show the capabilities of using functions in a program. Next week we’ll continue to build on our knowledge of advanced variables types called data collections.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   86   87   88   89   90   91   92   93   ...   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