Mundarija kirish I. Bob pythonning o'ziga xosligi va modullar modullarni skriptlar sifatida bajarish Modul qidirish yoʻli standart modullar 1 II.


Download 47.49 Kb.
bet7/10
Sana16.06.2023
Hajmi47.49 Kb.
#1507314
1   2   3   4   5   6   7   8   9   10
Bog'liq
7. PYTHON DASTURLASH TILIDA MODULLAR

Ro’yxatlar bilan ishlash
Ro‟yxatlar bilan ishlash uchun random modulida ikkita funksiya aniqlangan:
shuffle() funksiyasi ro‟yxatni tasodifiy ravishda aralashtiradi; choice() funksiyasi
ro‟yxatdan tasodifiy bitta elementni qaytaradi. ( 2.1.4-rasm)

numbers = [1, 2, 3, 4, 5, 6, 7, 8]

random.shuffle(numbers)

print(numbers) # 1

random_number = random.choice(numbers)

print(random_number)

2.1.4-rasm

2.2 math moduli


Ichki math moduli Pythonda matemetik, trigonometrik va logarifimik
amallarni bajaruvchi funksiyalarni o‟zida jamlaydi. Quyida ulardan bir nechtasi
sanab o‟tilgan:

  • pow(num, power) – num sonnini power darajaga ko‟taradi;

  • sqrt(num) – num sonini kvadratik ildizga oladi;

  • ceil(num) – soni eng yaqin katta butun songacha yaxlitlaydi;

  • floor(num) – soni eng yaqin kichik butun songacha yaxlitlaydi;

  • factorial(num) – sonning faktorialini hisoblaydi;

  • degrees(rad) – radiandan gradusga o‟tkazadi;

  • radians(grad) – gradusdan radianga o‟tkazadi;

  • cos(rad) – radianda burchak kosinusini hisoblaydi;

  • sin(rad) – radianda burchak sinusini hisoblaydi;

  • tan(rad) – radianda burchak tangensini hisoblaydi;

  • acos(rad) – radianda burchak arkkosinusini hisoblaydi;

  • asin(rad) – radianda burchak arksinusini hisoblaydi;

  • atan(rad) – radianda burchak arktangensini hisoblaydi;

  • log(n, base) – base asosga ko‟ra n ning logorifimini hisoblaydi;

  • log10(n) – n sonning o‟nli logorifimini hisoblaydi.

Bir qancha funksiyalarni qo‟lash bo‟yicha misol. (2.2.1-rasm)

import math

# 2 ni 3 darajasi

n1 = math.pow(2, 3)

print(n1) # 8

# yuqoridagi amalni quyidagicha bajarsa ham bo’ladi

n2 = 2 ** 3

print(n2)

# kvadrat ildizga olish

print(math.sqrt(9)) # 3

# yaqin katta butun son

print(math.ceil(4.56)) # 5

# yaqin kichik son

print(math.floor(4.56)) # 4

# radiandan gradusga o’tish

print(math.degrees(3.14159)) # 180

# gradusdan radianga o’tish

print(math.radians(180)) # 3.1415.....

# kosinus

print(math.cos(math.radians(60))) # 0.5

# sinus

print(math.sin(math.radians(90))) # 1.0

# tangens

print(math.tan(math.radians(0))) # 0.0

#logorifm

print(math.log(8, 2)) # 3.0

print(math.log10(100)) # 2.0

2.2.1-rasm
math modulida bir qator o‟zgarmas sonlar ham aniqlangan, PI va E. (2.2.2-rasm)

Import math

radius = 30

# 30 radiusli doira yuzasi

area = math.pi * math.pow(radius, 2)

print(area)

# 10 sonnining natural logarifmi

number = math.log(10, math.e)

print(number)

2.2.2-rasm

Download 47.49 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling