Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools



Download 2,02 Mb.
Pdf ko'rish
bet96/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   92   93   94   95   96   97   98   99   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Modulo Operator
Already,  you  should  know  that  we  have  an  important  operator  to  use  in  manipulating  numerical
values. Besides the popular addition, subtraction, multiplication, and division, we also have a unique
operator called the “modulo operator.” It is represented by the percentage (%) sign and returns the
remainder of a number divided by another. 
>>> 10 % 4
2
>>> 7 % 4
3
>>> 20 % 5
0
>>> 5 % 4
1
>>> 3 % 3


0
Note:   The operator does not tell us the number of times the number fits in the other number, rather
it tells us the reminder of the operator. For instance, the first example, which is 10 divided by 4, what
the  module  operator  does  here  is  to  return  the  reminder  when  the  division  takes  place.  In  this
situation,  it  returns  the  value  2  because  4  can  only  go  into  10  twice  and  with  2  remaining.
Interestingly, you can use this to ascertain if a particular number is odd or even. Let see how that
works out:
num = input(“Key in a number of your choice, and I will let you know if it is odd or even: “)
num = int(num)
if num % 2 == 0:
print (f “\nThe number you enter {num} is an even number.”)
else
print( f “\nThe number you enter {num} is an odd number. “)
Even numbers are numbers we can divide by two. Therefore, when a number modulo and two are
equivalent to zero, then the number is even. However, if it turns out otherwise, then it is even. Let us
run the program and assume that you insert 46.
Key in a number of your choice, and I will let you know if it is odd or even: 46
The number you entered is an even number



Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   92   93   94   95   96   97   98   99   ...   126




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