mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 13:31:07 +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
|
def main():
|
||||||
c = 0
|
def n31(a):# a = initial number
|
||||||
l = [a]
|
c = 0
|
||||||
while a != 1:
|
l = [a]
|
||||||
if a % 2 == 0:#if even divide it by 2
|
while a != 1:
|
||||||
a = a // 2
|
if a % 2 == 0:#if even divide it by 2
|
||||||
elif a % 2 == 1:#if odd 3n+1
|
a = a // 2
|
||||||
a = 3*a +1
|
elif a % 2 == 1:#if odd 3n+1
|
||||||
c += 1#counter
|
a = 3*a +1
|
||||||
l += [a]
|
c += 1#counter
|
||||||
print(a)#optional print
|
l += [a]
|
||||||
print("It took {0} steps.".format(c))#optional finish
|
print(a)#optional print
|
||||||
return l , c
|
print("It took {0} steps.".format(c))#optional finish
|
||||||
print(n31(43))
|
return l , c
|
||||||
|
print(n31(43))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
def findMin(x):
|
def main():
|
||||||
minNum = x[0]
|
def findMin(x):
|
||||||
for i in x:
|
minNum = x[0]
|
||||||
if minNum > i:
|
for i in x:
|
||||||
minNum = i
|
if minNum > i:
|
||||||
return minNum
|
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