Skip to content

Instantly share code, notes, and snippets.

@mafshin
Created March 5, 2022 08:46
Show Gist options
  • Save mafshin/fe43f915258c52e7a155ea663265c9a1 to your computer and use it in GitHub Desktop.
Save mafshin/fe43f915258c52e7a155ea663265c9a1 to your computer and use it in GitHub Desktop.
A Happy Birthday program for developers
from datetime import datetime
firstName = input('Enter your first name: ')
lastName = input('Enter your last name:');
birthdateInput = input('Enter your birthdate: YYYY-MM-DD: (e.g 2003-12-04):');
birthdate = datetime.fromisoformat(birthdateInput);
age = datetime.now() - birthdate
days = age.days
years = int(days / 365)
seconds = int(age.total_seconds())
minutes = int(seconds / 60)
hours = int(minutes / 60)
mercury_years = int(days / 88)
venus_years = int(days / 225)
mars_years = int(days / 687)
jupiter_years = days / 4332
saturn_years = days / 10756
oranus_years = days / 30688
neptune_years = days / 60190
light_distance = int((seconds * 300000) / 1000000000)
print()
print(f'Happy Birthday {firstName} {lastName}!')
print()
print('You are now:')
print(f'-- {years:<10} years old!')
print(f'-- {days:<10} days old!')
print(f'-- {hours:<10} hours old!')
print(f'-- {minutes:<10} minutes old!')
print(f'-- {seconds:<10} seconds old!')
print()
print('How old are you if you were living in other planets?')
print(f'-- {mercury_years:<10} years old in Mercury');
print(f'-- {venus_years:<10} years old in Venus');
print(f'-- {years:<10} years old in Earth')
print(f'-- {mars_years:<10} years old in Mars')
print(f'-- {jupiter_years:<10.2f} years old in Jupiter')
print(f'-- {saturn_years:<10.2f} years old in Saturn')
print(f'-- {oranus_years:<10.2f} years old in Oranus')
print(f'-- {neptune_years:<10.2f} years old in Neptune')
print()
print(f'Did you know in your life-time, light can travel {light_distance} billion kilometers?')
print()
print(f'Keep this program and run it again when you become {years * 2} (Earth) years old!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment