Hello everyone. Today is Monday..well not a big deal and I know everyone knows today is a Monday. Like you I'm not a big fan of Monday, although nowadays I'm waiting eagerly for this day of the week as I get to watch a Game of Thrones episode on this day and I'm sure most of you can reciprocate the same feeling. The only thing I hate the most is the long wait till Monday night till I return to home from office and get to watch that episode for which I wait for one whole week and here I am in office waiting for the day to get over soon.
The plan
To kill the time I do one of the thing that I love the most. Yes, you guessed right? I code. So, I decided to fool around some python programming code to kill the boredom. Without much ado let's code :) I decided to device a python program that would help me to devise a "collatz sequence" In case you are thinking what a "collatz sequence" is then dive into this link here.
For more understanding on python check the Automate the Boring Stuff with Python: Practical Programming for Total Beginners
The code
The below function is collatz() has one parameter named number. If number is even, then collatz() should print number // 2 . If number is odd, then collatz() should print and return 3 * number + 1.
The below program let's user provide an integer and the program then keeps calling the function collatz() till the function returns 1. It's a simple program but trust me it's very interesting, the reason why it's interesting can be found in the link . Go ahead and have some fun and thank me later.
Comments
Post a Comment