Everyone who has read the book or seen the film Da Vinci Code has heard about the Fibonacci sequence. The sequence looks a bit like this: In recent years a zero has been added to the front of the sequence, and it it this sequence I will be programming. The Fibinacci sequence can be defined …
Continue reading Fibonacci
Category:Python
validDate Revisited – Python
I have just realised a mistake in my validDate Function. The mistake is that it only validates the day and not the month or year, i also realised that it would validate the day even if the day is zero so I need to fix this. It was only when I was creating the Java …
Continue reading validDate Revisited – Python
Valid Date
Another good function which would come in handy for Zeller is a function to make sure the date which was inputted is valid and display a message if the program has encountered an invalid date. For this function I will be using my inArray function which I wrote in a previous post. I will utilise …
Continue reading Valid Date
In Array
Something I am constantly wanting to do in a lot of programs is see if a value is in an array. For another function which I wish to write to add to the Zeller program this will come in handy. The basic algorithm looks like this: SET value TO RequiredValueSET array TO ArrayToSearchSET isIn TO …
Continue reading In Array
Factoral and Recursion
We all remember factorals from school but to remind us what they are, a factoral is the product of all the positive integers less than or equal to the initial number(n): For example: Strangely 0!=1 there is a mathematical proof which states why but I will not be expanding on it here, I will however …
Continue reading Factoral and Recursion
Zeller Congruence (The Program)
Now that we know that the algorithm works we can know build a solution We will start by adding code to perform the calculation for this we will need to import the Python math module so that we can use the built in floor function. We will also have to take into account the months …
Continue reading Zeller Congruence (The Program)
Prime Numbers
Anyone that has studied secondary school mathematics knows what a prime number is but just to recap the definition of a prime number is any number which is only divisible by 1 and itself. 1 is however not a prime number as it is only divisible by itself, and other than 2 all prime numbers …
Continue reading Prime Numbers
Is Odd? or is Even?
In my last post I wrote a program to print the Collatz Conjecture for a particular number. In this program I had to check if the number is odd or not(even). For my next program I will need to do this check again so I have decided to write a very short function to check …
Continue reading Is Odd? or is Even?
Collatz Conjecture (The Code)
In the This program just returns the value for a single value so we need to wirte an extra function to get the sequence: The code above adds the values in the sequence to an array and then prints simply prints the array to the screen, running the code above produces the following output: This …
Continue reading Collatz Conjecture (The Code)