Python math.comb() နည်းလမ်း
ဥပမာ
n items မှ k အရာများကို ရွေးချယ်ရန် ဖြစ်နိုင်ခြေစုစုပေါင်းအရေအတွက်ကို ရှာပါ
# Import math Library
import math
# Initialize the number of
items to choose from
n = 7
# Initialize the number of possibilities
to choose
k = 5
# Print total number of possible combinations
print
(math.comb(n, k))
ရလဒ်မှာ-
21
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်းသည် ပေါင်းစပ်မှုဟုလည်းသိကြသော ထပ်ခါတလဲလဲမလုပ်ဘဲ n ဖြစ်နိုင်ချေများမှ k မသတ်မှတ်ထားသော ရလဒ်များကို ကောက်ယူ သည့် math.comb()
နည်းလမ်းအရေအတွက်ကို ပြန်ပေးသည်
။
မှတ်ချက်- ဤနည်းလမ်းတွင် ဖြတ်သွားသော ဘောင်များသည် အပေါင်းကိန်းပြည့်များ ဖြစ်ရပါမည်။
အထားအသို
math.comb(n, k)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
n | Required. Positive integers of items to choose from |
k | Required. Positive integers of items to choose |
မှတ်ချက်- k ၏ တန်ဖိုးသည် n ၏တန်ဖိုးထက်ကြီး ပါက ရလဒ်အနေဖြင့် 0 သို့ပြန်သွားမည်ဖြစ်သည်။
မှတ်ချက်- ကန့်သတ်ချက်များ အနုတ်လက္ခဏာဖြစ်ပါက ValueError ဖြစ်ပေါ်ပါသည်။ ကန့်သတ်ချက်များသည် ကိန်းပြည့်မဟုတ်ပါက၊ TypeError တစ်ခု ဖြစ်ပေါ်ပါသည်။
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | ပေါင်းစပ် အရေအတွက် int စုစုပေါင်းကို ကိုယ်စားပြုသော တန်ဖိုး |
---|---|
Python ဗားရှင်း- | ၃.၈ |