# Biorhythm Values (Python)

When I first met folks in Las Vegas that used biorhythm values of the top players in a team to place their bet, I thought they were a little odd. Some of them were successful, but I am sure biorhythms were not the only thing they considered. You can read more about biorhythms at:
http://en.wikipedia.org/wiki/Biorhythm

This snippet shows a simple Python code to calculate the three standard biorhythm values centered around the present day, based on the your age in days. To expand the program you can use VPython to plot the values, let's say for the period of a month. See:
http://www.daniweb.com/code/snippet376.html

2,249 Views
About the Author

Scientist

``````# calculate the biorhythm value for today and the days around it
# see: http://en.wikipedia.org/wiki/Biorhythm
# tested with Python24      vegaseat     15may2006

import datetime
from math import sin

def getBiorhythm(zd):
"""
returns the three biorhythm values, given the days since birth zd
50 is center value, higher values are better
"""
pi = 3.14159
zd = int(zd)
physical = int(50 * (1 + sin((zd / 23.0 - (zd / 23)) * 360 * pi / 180)))
emotion = int(50 * (1 + sin((zd / 28.0 - (zd / 28)) * 360 * pi / 180)))
intellect = int(50 * (1 + sin((zd / 33.0 - (zd / 33)) * 360 * pi / 180)))
return physical, emotion, intellect

print "This program calculates your biorhythm values based on your age in days."
print "The values for a seven day period are given, with today in the center."
print "This allows you to see, if you are in a decreasing or increasing cycle."
print

bd = raw_input("Enter your birthday (format = mm/dd/yyyy): ")

# split the string into month, day, year
dL = bd.split("/")

# convert to format datetime.date(year, month, day))
birthday = datetime.date(int(dL), int(dL), int(dL))

# get todays date
today = datetime.date.today()

# calculate age in days since birth
age = (today - birthday).days

p = []  # physical well-being list over range of 7 days
e = []  # emotional well-being list over range of 7 days
i = []  # intellectual well-being list over range of 7 days

for ax in range(age-3, age+4):
px, ex, ix = getBiorhythm(ax)
p.append(px)
e.append(ex)
i.append(ix)

print "-"*58

print "Birthday     =", birthday.strftime("%d%b%Y")
print "Today        =", today.strftime("%d%b%Y")
print "Age in days  =", age

print "-"*58

print "Here are your biorhythm values (higher values best):"
print "Days from today %5s %5s %5s %5s %5s %5s %5s" % ('-3', '-2', '-1', '0', '+1', '+2', '+3')
print "Physical     :  %5d %5s %5s %5s %5s %5s %5s" % (p, p, p, p, p, p, p)
print "Emotional    :  %5d %5s %5s %5s %5s %5s %5s" % (e, e, e, e, e, e, e)
print "Intellectual :  %5d %5s %5s %5s %5s %5s %5s" % (i, i, i, i, i, i, i)

print "-"*58``````