Skip to content

Instantly share code, notes, and snippets.

@Half-Shot
Last active December 27, 2015 16:49
Show Gist options
  • Save Half-Shot/7357390 to your computer and use it in GitHub Desktop.
Save Half-Shot/7357390 to your computer and use it in GitHub Desktop.
Fibonacci Sequence
#Fibonacci Sequence
#Have fun, Dr. Half-Shot
#Checks if a number is an integer.
def IsInt(val):
try:
int(val)
except:
return False
return True
def Main():
CountTo = input("Enter a number to count to (non-integer for forever):")
if IsInt(CountTo): #If the number is an integer
print("Counting from 0 to", CountTo) #Give the user a friendly message.
Sequence(int(CountTo))# Yes > Use specfied number to start the sequence.
else:
print("End of it.")
Sequence(-1) #Runs indefinately
def Sequence(val):
x = 0 #First
y = 1 #Before nOne
print("0", end="") #Add a zero, its proper.
while(x < val or val == -1):
new = x + y
y = x
x = new
print("",x, end="")
print("\nFinished")
if __name__ == "__main__":
Main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment