Oli otya, abavubuka bange! Lwaki tugenda kukola ku Python n’okusaba ekizikiza ky’amasanyalaze, ekirina okuwa abakozi b’ebyokulabirako amaanyi okukola obulungi mu kwetegereza ebintu ebikalu. N’ekikyu, n’oyagala okuva mu muwendo ogumu oba okwawukana, ekigambo kino kisobola okukulaga ekizikiza n’ebyobukodyo bingi, era ky’ogenda kusaba mu nkola ezo ezikozesa ekizikiza.
Python n’ekizikiza ky’amasanyalaze
Ekizikiza ky’amasanyalaze mu Python (math library) ky’ekikula ky’amaanyi era kyawandiikiddwa okusaba ebikalu mu nkola z’amasanyalaze. N’akabasa, osobola okufuna ekizikiza ky’amaanyi mu nsonda ezikalu z’amasanyalaze. N’akabasa, twandikire obukodyo bwa Python obukolebwa.
import math # 1. Banga ya π pi_value = math.pi print("Banga ya π: ", pi_value) # 2. Eby’amasanyalaze: sin, cos, tan angle = math.radians(30) # Tusinge mu gradi oba radians sin_value = math.sin(angle) cos_value = math.cos(angle) tan_value = math.tan(angle) print("sin(30°): ", sin_value) print("cos(30°): ", cos_value) print("tan(30°): ", tan_value) # 3. Logarithm y’amasanyalaze log_value = math.log(10) print("Logarithm y’amasanyalaze ya 10: ", log_value) # 4. Nzoto ya mwasi sqrt_value = math.sqrt(16) print("Nzoto ya mwasi ya 16: ", sqrt_value) # 5. Ekitongole abs_value = math.fabs(-5) print("Ekitongole ky’amaanyi ya -5: ", abs_value)
Ekitone:
Banga ya π: 3.141592653589793 sin(30°): 0.49999999999999994 cos(30°): 0.8660254037844387 tan(30°): 0.5773502691896257 Logarithm y’amasanyalaze ya 10: 2.302585092994046 Nzoto ya mwasi ya 16: 4.0 Ekitongole ky’amaanyi ya -5: 5.0
Ng’ogenda okulaba, ekizikiza ky’amasanyalaze mu Python kisobola okuwa ebikalu mu nkola ezikozesebwa mu kitiibwa. Okubeera ne banzirizibwa, tekirina kusaba buli ky’ofuna bungi.
Akabasa: Okukola obulungi ku mwasi
Kati tusaba kukola akabasa k’okuziika mwasi, nga tusaba okwekenya A = π * r², ng’eyitibwa r mwasi.
def area_circle(radius): return math.pi * math.pow(radius, 2) radius = 5 area = area_circle(radius) print(f"Obulungi bw’amasanyalaze n’ewaka {radius}: {area}")
Ekitone:
Obulungi bw’amasanyalaze n’ewaka 5: 78.53981633974483
Obutukirivu
Mu nkola ya nsonga, tusabye kukola okwekenya Python n’ekizikiza ky’amasanyalaze okusobola okwekenya obulungi bw’amasanyalaze. Ng’ogenda okukola n’eyandi, ojja kufuna obulungi bw’amasanyalaze era okufuna obulungi bw’amasanyalaze nga omanyi by’osaba.