mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 05:21:09 +00:00
name = main
added if __name__ == '__main__'
This commit is contained in:
parent
9ded2c3d22
commit
261d721b22
|
@ -1,14 +1,18 @@
|
|||
def n31(a):# a = initial number
|
||||
c = 0
|
||||
l = [a]
|
||||
while a != 1:
|
||||
if a % 2 == 0:#if even divide it by 2
|
||||
a = a // 2
|
||||
elif a % 2 == 1:#if odd 3n+1
|
||||
a = 3*a +1
|
||||
c += 1#counter
|
||||
l += [a]
|
||||
print(a)#optional print
|
||||
print("It took {0} steps.".format(c))#optional finish
|
||||
return l , c
|
||||
print(n31(43))
|
||||
def main():
|
||||
def n31(a):# a = initial number
|
||||
c = 0
|
||||
l = [a]
|
||||
while a != 1:
|
||||
if a % 2 == 0:#if even divide it by 2
|
||||
a = a // 2
|
||||
elif a % 2 == 1:#if odd 3n+1
|
||||
a = 3*a +1
|
||||
c += 1#counter
|
||||
l += [a]
|
||||
print(a)#optional print
|
||||
print("It took {0} steps.".format(c))#optional finish
|
||||
return l , c
|
||||
print(n31(43))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
def findMin(x):
|
||||
minNum = x[0]
|
||||
for i in x:
|
||||
if minNum > i:
|
||||
minNum = i
|
||||
return minNum
|
||||
def main():
|
||||
def findMin(x):
|
||||
minNum = x[0]
|
||||
for i in x:
|
||||
if minNum > i:
|
||||
minNum = i
|
||||
return minNum
|
||||
|
||||
print(findMin([0,1,2,3,4,5,-3,24,-56])) # = -56
|
||||
print(findMin([0,1,2,3,4,5,-3,24,-56])) # = -56
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user