n=int(input("Enter number: "))
while n != 1:
print(n)
if n%2==0:
n//= 2
else:
n = (n*3)+1
I wrote my code in python 3.8. If you want to print the 1, keep the last line of code otherwise delete it.
5.7m questions
7.5m answers