ในบทความนี้ เราจะเรียนรู้เกี่ยวกับวิธีแก้ปัญหาและแนวทางแก้ไขปัญหาที่กำหนด
คำชี้แจงปัญหา −ให้ตัวเลข “n” หาจำนวนตัวหารทั้งหมดเป็นคู่หรือคี่
ในแนวทางนี้ เราจะหาตัวหารทั้งหมดและตรวจสอบว่าจำนวนตัวหารเป็นคู่หรือคี่
การใช้งานได้รับด้านล่าง -
ตัวอย่าง
import math
def countDivisors(n) :
count = 0
# calculating all the divisors
root=int(math.sqrt(n))+2
for i in range(1, root) :
if (n % i == 0) :
# If divisors are equal,increment count by one Otherwise increment count by 2
if( n // i == i) :
count = count + 1
else :
count = count + 2
if (count % 2 == 0) : def countDivisors(n) :
count = 0
# calculating all the divisors
root=int(math.sqrt(n))+2
for i in range(1, root) :
if (n % i == 0) :
# If divisors are equal,increment count by one Otherwise increment count by 2
if( n // i == i) :
count = count + 1
else :
count = count + 2
if (count % 2 == 0) :
print("Even")
else :
print("Odd")
# Driver program to test above function */
print("The count of divisor: ")
countDivisors(100)
print("Even")
else :
print("Odd")
# Driver program to test above function */
print("The count of divisor: ")
countDivisors(100) ผลลัพธ์
120 No
ตัวแปรทั้งหมดถูกประกาศในขอบเขตสากลดังแสดงในภาพด้านล่าง

บทสรุป
ในบทความนี้ เราได้เรียนรู้เกี่ยวกับวิธีการตรวจสอบว่าจำนวนตัวหารเป็นเลขคู่หรือคี่ของตัวเลขที่กำหนดหรือไม่