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


Step #1: Ask User for Calculation to Be Performed



Download 2,61 Mb.
bet53/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   49   50   51   52   53   54   55   56   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Step #1: Ask User for Calculation to Be Performed


For each one of these steps, let’s put the code in separate cells. This will allow us to section of the specific steps for our project, making it easier to test each step. The first step is to ask the user to input the mathematical operation to be performed (add, subtract, etc.):

# step 1: ask user for calculation to be performed
operation = input("Would you like to add/subtract/multiply/divide? ").lower( ) print( "You chose { }.".format(operation) ) # for testing purposes

Go ahead and run that cell. Depending on what the user inputs, your output will print what they chose. You’ll notice that on the line where we accept the input, we also convert it to lowercase right away. This is to avoid case-sensitive issues later. Our print statement is simply for testing purposes on this cell only and will be removed later.

Step #2: Ask for Numbers, Alert Order Matters


In the cell below step #1, we’ll need to create the next step of our logic. Here, we ask the user to input a couple of numbers and output those numbers for testing purposes:

# step 2: ask for numbers, alert order matters for subtracting and dividing if operation == "subtract" or operation == "divide": print( "You chose { }.".format(operation) ) print("Please keep in mind that the order of your numbers matter.") num1 = input("What is the first number? ") num2 = input("What is the second number? ") print( "First Number: { }".format(num1) ) # for testing purposes print( "Second Number: { }".format(num2) ) # for testing purposes

Go ahead and run that cell. Notice that we put in a print statement alerting the user that if they chose subtraction or division, the order of numbers matters. This is important as num1 will always be on the left side of the operator (in our program), which makes a huge difference.
Note rerun the previous cell if you get an error for undefined.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   49   50   51   52   53   54   55   56   ...   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