1-masala.
A butun soni berilgan. Jumlani rostlikka tekshiring: “A soni toq son”.
a=int(input('a='))
print(bool(a%2==1))
Ikkita butun A va В sonlari berilgan. Jumlani
rostlikka tekshiring: “A>2 va B<=3”.
a=int(input('a='))
b=int(input('b='
)) c=bool(a>2
and b<=3)
print(c)
Uchta А, В, С butun sonlar berilgan. Jumlani rostlikka
tekshiring: “A<=В<=С”
a=int(input('a='))
b=int(input('b='))
c=int(input('c='))
hisoblash=bool(a<=b
and b<=c)
print(hisoblash)
Ikkita butun A va В sonlari berilgan. Jumlani
rostlikka tekshiring: “A va В sonlari toq sonlar”.
a=int(input('a='))
b=int(input('b='))
toq_son=bool(a%2==1 and
b%2==1)
print(a,'va',b,'sonlari toq
sonlar:',toq_son)
Ikkita butun A va В sonlari berilgan. Jumlani rostlikka
tekshiring: “A vaВ sonlarning kamida bittasi toq son”.
a=int(input('a='))
b=int(input('b='))
bitta_toq=bool(a%2==1
or b%2==1)
print(a,'va',b,'sonlarning
kamida bittasi toq
son:',bitta_toq)
Uchta А, В, С butun sonlar berilgan. Jumlani rostlikka
tekshiring: “А, В, С sonlarning har biri musbat”
.
a=int(input('a='))
b=int(input('b='))
c=int(input('c='))
musbat=bool(a>0 and
b>0 and c>0)
print(a,',',b,',',c,'sonlarnin
g har biri
musbat:',musbat)
Musbat butun son berilgan. Jumlani rostlikka tekshiring: “Berilgan
son ikki xonali juft son”.
a=int(input('a='))
b=bool(a>9 and a<100
and a%2==0)
print('Berilgan son ikki
xonali juft son:',b)
Uch xonali son berilgan. Jumlani rostlikka tekshiring: “Ushbu sonning
barcha raqamlari xar xil”.
import math
a=int(input('a='))
x=math.floor(a/100)
y=math.floor(a/10)%10
z=math.floor(a/10)
natija=bool(x!=y and x!=z and
y!=z)print('Uch xonali sonning
barcha raqamlari har xil:',natija)
Ma`lumot kiritish formatlari:
Topshiriq: Birorta matn kiriting va uning uzunligini len komandasi orqali toping
Matn formatini o`zgartirish
Python’da list-bu tartiblangan va o’zgaruvchan ro`yhat []
Python’da tuple-bu tartiblangan va o’zgarmas ro`yhat ()
Python’da set -bu tartiblanmagan va indekslanmagan ro`yhat {}
Python’da dictionary -tartiblanmagan, o`zgaruvchan va indekslangan
to’plam {}
Python’da ro`yhatlar
>>> thisset={'civi','banana','apple','cherry'}
>>> print(thisset)
{'banana', 'civi', 'cherry', 'apple'}
>>> thisset=['civi','banana','apple','cherry']
>>> print(thisset)
['civi', 'banana', 'apple', 'cherry']
>>> type(thisset)
>>> n={'civi','banana','apple'}
>>> type(n)
>>> print('apple' in thisset)
True
>>> print('onion' in thisset)
False
>>> n.add('orange')
>>> print(n)
{'banana', 'civi', 'apple', 'orange'}
--------------------------------------
To`plamlar
------------------------------------
>>> thisset={'cici' , 'banan'}
>>> print(thisset)
{'banan', 'cici'}
>>> thisset.add('mohito')
>>> print(thisset)
{'banan', 'cici', 'mohito'}
>>> thisset.remove('cici')
>>> print(thisset)
{'banan', 'mohito'}
>>> del thisset
>>> thisset
Traceback (most recent call last):
File "
", line 1, in
thisset
NameError: name 'thisset' is not defined
---------------------------------------------
>>> thisset={'civi' , 'banana'}
>>> print(thisset)
{'banana', 'civi'}
>>> thisset.update(['kivi', 'banan'])
>>> print(thisset)
{'banana', 'civi', 'banan', 'kivi'}
>>> thisset.remove('banana')
>>> thisset.remove('civi')
>>> print(thisset)
{'banan', 'kivi'}
>>> thisset.clear()
>>> thisset
set()
>>> set1={'a', 'b' , 'c'}
>>> set2={1, 2, 3}
>>> set3=set1.union(set2)
>>> print(set3)
{'b', 1, 2, 'c', 3, 'a'}
>>> set1.update(set2)
>>> set1
{'b', 1, 2, 'c', 3, 'a'}
100>
Do'stlaringiz bilan baham: |