diff --git a/Largest of the three numbers.py b/Largest of the three numbers.py index 7d8f9488..1f569224 100644 --- a/Largest of the three numbers.py +++ b/Largest of the three numbers.py @@ -2,15 +2,11 @@ # Take the input from the user -num1 = float(input("Enter the first number - ")) -num2 = float(input("Enter the second number - ")) -num3 = float(input("Enter the third number - ")) - -if(num1 >= num2) and (num1 >= num3): - largest = num1 -elif(num2 >= num3) and (num2 >= num1): - largest = num2 -else: - largest = num3 - -print("The largest number is", largest) \ No newline at end of file +def maximum(a, b, c): + list = [a, b, c] + return max(list) + +a = float(input("Enter the first number - ")) +b = float(input("Enter the second number - ")) +c = float(input("Enter the third number - ")) +print(maximum(a, b, c)) \ No newline at end of file diff --git a/sum-of-divisors.py b/sum-of-divisors.py index de5d4c15..8ac0dc8d 100644 --- a/sum-of-divisors.py +++ b/sum-of-divisors.py @@ -1,30 +1,20 @@ -""" -Python program to find sum of divisors of a number n, -for example: -print(sum_divisors(0)) -# 0 -print(sum_divisors(3)) -# Should sum of 1 -# 1 -print(sum_divisors(36)) -# Should sum of 1+2+3+4+6+9+12+18 -# 55 -print(sum_divisors(102)) -# Should be sum of 2+3+6+17+34+51 -# 114 - """ - - -def sum_divisors(n): - sum = 0 - x = 1 - while x < n: - if n % x == 0: - sum += x - else: - x += 1 - - return sum - +import math + +def divSum(num) : + + result = 0 + i = 2 + while i<= (math.sqrt(num)) : + + if (num % i == 0) : + + if (i == (num / i)) : + result = result + i; + else : + result = result + (i + num/i); + i = i + 1 + return (result + 1); +num = 102 +print (divSum(num)) \ No newline at end of file