Write a python program to find sum of odd factors of a number with the output.

**How to find sum of even factors of a number in Python?**

Copy the below python program and execute it to see the program output. I have executed it shared the program output after the program.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import math # Returns sum of all even factors of n. def sumofFactors(n) : # If n is odd if (n % 2 != 0) : return 0 #all prime factors res = 1 for i in range(2, (int)(math.sqrt(n)) + 1) : count = 0 curr_sum = 1 curr_term = 1 while (n % i == 0) : count= count + 1 n = n // i # here we remove the 2^0 that is 1. All other factors if (i == 2 and count == 1) : curr_sum = 0 curr_term = curr_term * i curr_sum = curr_sum + curr_term res = res * curr_sum # if n is prime number if (n >= 2) : res = res * (1 + n) return res # main n = 20 print(sumofFactors(n)) |

**Program Output**

1 | 36 |

Thatâ€™s all, we hope this program helped you!

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

- How to define a function in JavaScript?
- How do you reuse elements with key attribute?
- What are iterators in Python?
- How to know if a flutter image has been seen by the user?
- How does WordPress create URLs that Apache knows about?
- Linear search program in Python
- How do I get the path of the assembly the code is in?
- Is there any way to use get_template_part() with folders?
- What are the basic data types in C?
- How to run a task in the background in flutter?
- What is AOT compiler?
- How to find nth highest salary of employees in Java?
- How to disable WooCommerce single product page?
- What are the various security contexts in Angular?
- How to tell when a NetworkImage has finished loading?

We use cookies to ensure that we give you the best experience and use cookies in order to personalize the advertising that you see on our website. Read more about our Privacy Policy.Got it!