Biorhythms with Python
Biorhythms with Python
Write a Python program that calculates and displays the intellectual, emotional, and physical biorhythm cycles of a user, based on his/her birth date. The program should:
1. Prompt the user to enter his/her birth date (year, month, and day).
2. Calculate the user’s current biorhythm cycles using the following formulas:
– Physical cycle: sin(2Ï€ * days_since_birth / 23)
– Emotional cycle: sin(2Ï€ * days_since_birth / 28)
– Intellectual cycle: sin(2Ï€ * days_since_birth / 33)
3. Display the calculated values for the user’s physical, emotional, and intellectual biorhythm cycles.
Steps
- Import the math and datetime libraries
- Define the function
"calculate_biorhythms"to calculate the biorhythm cycles and days from the birthday until today. - Prompt the user to enter his/her birth date and then calculate the physical, emotional, and intellectual cycles based on today’s date using the
"calculate_biorhythms"Â function.
Expected output
Enter the year of your birth date: 1979 Enter the month of your birth date: 06 Enter the day of your birth date: 17 Physical cycle: -0.6310879443257876 Emotional cycle: -1.5087896157750027e-13 Intellectual cycle: 0.3716624556603878
Source Code
import datetime
import math
# Function to calculate the biorhythm cycles
def calculate_biorhythms(birth_date):
today = datetime.date.today()
days_since_birth = (today - birth_date).days
# Calculate the physical, emotional, and intellectual cycles
physical_cycle = math.sin(2 * math.pi * days_since_birth / 23)
emotional_cycle = math.sin(2 * math.pi * days_since_birth / 28)
intellectual_cycle = math.sin(2 * math.pi * days_since_birth / 33)
return physical_cycle, emotional_cycle, intellectual_cycle
# Prompt the user to enter their birth date
year = int(input("Enter the year of your birth date: "))
month = int(input("Enter the month of your birth date: "))
day = int(input("Enter the day of your birth date: "))
birth_date = datetime.date(year, month, day)
# Calculate the biorhythm cycles
physical, emotional, intellectual = calculate_biorhythms(birth_date)
# Display the results
print("Physical cycle:", physical)
print("Emotional cycle:", emotional)
print("Intellectual cycle:", intellectual)
Keep practicing coding with Python real projects or different Python problems.