def collatz(number): while number != 1: if number % 2 == 0: number = number // 2 print(number) elif number % 2 == 1: number = 3 * number + 1 print(number) print('Enter number: ') number = int(input()) collatz(number)
<strong>-------------------------------------------<br></strong>
Enter number:
3
10
5
16
8
4
2
1
Suddenly it feels like there is nothing to comment on Yes, the tips in the book are all mentioned
The Github address of Stepping into the Pit:
I am learning, there is no high-quality code, so take your time.
<br>
The above is the detailed content of python programming quick start example. For more information, please follow other related articles on the PHP Chinese website!