[ad_1]
n = enter('joe numba: ')
whereas(n % 2) == 0:
n = n/2
print(n)
whereas(n % 2) != 0:
n = n * 3 + 1
print(n)
if(n) == 1:
break
else:
proceed
whereas(n % 2) != 0:
n = n * 3 + 1
print(n)
whereas(n % 2) == 0:
n = n/2
print(n)
if(n) == 1:
break
else:
proceed
Downside no.1:
i used to be coding on my Iphone (Python2IDE) and this code was usually operating, then i needed to strive it out on my pc but it surely began displaying me this error:
Traceback (most up-to-date name final):
File "C:UsersLenovoPycharmProjectspythonProjectmain.py", line 4, in <module>
whereas (n % 2) == 0:
TypeError: not all arguments transformed throughout string formatting
and this system didn´t wish to work…
Downside no.2:
on my telephone when this runs it doesn´t wish to cease itself except i shut the app… i must know why and how one can make it cease at 1. I attempted to place there whereas
assertion twice, as a result of when i didn´t, the code solely both labored for even numbers or just for odd ones, i additionally must know why this occurs… i attempted to make use of if
as an alternative of whereas
, but it surely didn´t make a cycle and the code was usable solely as soon as (similar to i anticipated). My program is made to check if each quantity fits the Collatz conjecture (simply sayin, in case that might assist with fixing my drawback)
thanks.
[ad_2]