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



Download 2,61 Mb.
bet30/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   26   27   28   29   30   31   32   33   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Using Multiple Variables


In almost any program you’ll write, you’re going to need to perform some calculations or manipulation on variables. In the following code, we access the values from previously declared variables and add them together to create a sum. Make sure that the previous cells have been run before running this cell. Let’s go ahead and put this in a new cell:

# using two variables to create another variable result = num1 + num2 print(result)

After running this cell, you’ll notice that it added 5 and 8.4 together to output 13.4.
Note If you get an error saying that a variable doesn’t exist, try running the cell where that variable is declared first.

Using Operators on Numerical Variables


Think of Python as a calculator, where we can alter any variables we want. In the following code, we alter the “result” variable defined previously:

# adding, deleting, multiplying, dividing from a variable result += 1 # same as saying result = result + 1 print(result) result *= num1 # same as saying result = result * num1 print(result)

Go ahead and run the cell. In the first line, we added 1 to the result, then later we multiplied it by the value of “num1,” which is 5. All the while, the computer saved the result variable so we could continue to edit it. Then we print the result, which comes out to 72.0.

Overwriting Previously Created Variables


Python makes it easy for us to change the value of a variable, by simply re-declaring it. In some languages you would have to define the data type, but Python handles all of that for us. We’ve seen this occur with the preceding result variable, but it’s worth noting in its own cell:

# defining a variable and overwriting it's value name = 'John' print(name) name = 'Sam' print(name)

Go ahead and run that in a new cell. You’ll notice that the output shows “John” and
Sam”. The location of when you access or re-declare your variables matter; keep that in mind.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   26   27   28   29   30   31   32   33   ...   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