mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Editing base64, Adding average file, Editing find_lcm (#673)
* avrage.py
calculate and print the avrage of number list.
* Update base64_cipher.py
encoding and decoding base64 without any module.
* Update and rename avrage.py to average.py
* update find_lcm algorithm
I made find_lcm more efficient form O(num1*num2) to O(min{num1,num2}).
This commit is contained in:
committed by
Chetan Kaushik
parent
ac28125060
commit
c92b02cfa3
14
Maths/average.py
Normal file
14
Maths/average.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def average(nums):
|
||||
sum = 0
|
||||
n = 0
|
||||
for x in nums:
|
||||
sum += x
|
||||
n += 1
|
||||
avg = sum / n
|
||||
print(avg)
|
||||
|
||||
def main():
|
||||
average([2, 4, 6, 8, 20, 50, 70])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,10 +1,11 @@
|
||||
def find_lcm(num_1, num_2):
|
||||
max = num_1 if num_1 > num_2 else num_2
|
||||
lcm = max
|
||||
while (True):
|
||||
if ((max % num_1 == 0) and (max % num_2 == 0)):
|
||||
if ((lcm % num_1 == 0) and (lcm % num_2 == 0)):
|
||||
break
|
||||
max += 1
|
||||
return max
|
||||
lcm += max
|
||||
return lcm
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user