ตรวจสอบก่อนนำไปใช้
เปรียบเทียบการทำงานจริงกับผลที่คาดหวัง หากการตรวจสอบไม่ผ่าน ให้หาสาเหตุก่อนแก้ไขเพิ่มเติม
คำนวณกำลังจำนวนเต็มมอดูลัสจำนวนเต็มบวกด้วยการยกกำลังสองซ้ำ.
def mod_power(base, exponent, modulus):
if any(type(v) is not int for v in (base, exponent, modulus)):
raise ValueError("operand.integer")
if exponent < 0 or modulus <= 0:
raise ValueError("operand.range")
result = 1 % modulus
base %= modulus
while exponent:
if exponent & 1:
result = result * base % modulus
base = base * base % modulus
exponent >>= 1
return resultเปรียบเทียบการทำงานจริงกับผลที่คาดหวัง หากการตรวจสอบไม่ผ่าน ให้หาสาเหตุก่อนแก้ไขเพิ่มเติม
ตั้งค่า endpoint ที่รองรับ OpenAI หรือ Anthropic ด้วย URL หลักและคีย์ API หากจำเป็น ทดสอบการเชื่อมต่อ เซิร์ฟเวอร์โมเดลในเครื่องต้องทำงานอยู่ เครื่องมือระยะไกลอาจส่งข้อมูลแยกต่างหาก
ทดสอบฐานลบ เลขชี้กำลังศูนย์และมอดูลัสหนึ่ง พร้อมปฏิเสธเลขชี้กำลังลบและตัวถูกดำเนินการที่ไม่ใช่จำนวนเต็มหรือเป็นบูลีนก่อนคูณ.
def mod_power(base, exponent, modulus):
if any(type(v) is not int for v in (base, exponent, modulus)):
raise ValueError("operand.integer")
if exponent < 0 or modulus <= 0:
raise ValueError("operand.range")
result = 1 % modulus
base %= modulus
while exponent:
if exponent & 1:
result = result * base % modulus
base = base * base % modulus
exponent >>= 1
return result