RedPanther
Posts: 39
Joined: Thu Sep 12, 2019 9:20 pm

My first Python app--Age Calculator(need suggestions!)

Mon Oct 21, 2019 1:06 am

Today I took the time to trial and error my way through designing my own app from the ground up using Python. This is the first time I have ever coded anything. While my app works great for its originally intended purpose, I would like to add more to it. If you have any suggestions, please help!

Code: Select all

# This app was designed to easily calculate the age of
# something/someone. Simply change the corresponding
# variables below and run the program to get an answer.
# Program currently only tells age in years. I will add
# months, weeks, and days to calculations soon.
# 
# There are still glitches for some dates within one
# year prior(no answer given). Remember, this is an age
# calculator based on known dates. It does not count the 
# differences in months or days(yet). Scroll down to see most
# current possible outputs this app may yield.
#
# Change theses variables to the date you want calculated.

a = birth_month = 11
b = birth_day = 17
c = birth_year = 1986

# Make sure these variables match the current date.

d = this_month = 10
e = this_day = 20
f = this_year = 2019

#
#
# Do NOT change these equations!
x = your_age1 = ((f - c) - 1)
y = your_age2 = (x + 1)
#
#
# Do NOT change the output lines!
if(d<a)and(f-c>0):
    print('You are ' + str(x) + ' years old.')
if(d>a)and(f-c>0):
    print('You are ' + str(y) + ' years old.')
if(a==d)and(e>b)and(f-c>0):
    print('You are ' + str(y) + ' years old.')
if(a==d)and(e<b)and(f-c>0):
    print('You are ' + str(x) + ' years old.')
if((d-a)<<1)and(c==f)and(b<e):
    print('You are ' + str(y) + ' years old.')
if(a==d)and(b==e)and(f-c>0):
    print('You are ' + str(y) + ' years old. HAPPY BIRTHDAY!')
if((f-c)<0):
    print('You are not born yet.')
if(a==d)and(c==f)and(b>e):
    print('You are not born yet.')
if(a>d)and(c==f):
    print('You are not born yet.')
if(a==d)and(b==e)and(x<<1):
    print('Welcome to the world!')
#
# Notes:
#
# Add day/month/year calculator(days per year, days
# per month, days per week, months per year, leap-year
# adjustment) for more accurate calculations. Also add
# "ask for input" so program can be run interactively
# via terminal.
# If you find any glitches such as no answer given
# or incorrect answer given or would like to make a
# suggestion, please notify me.
#
# Thanks for coding with RedPanther!
#
#

Again, this is my first time EVER writing any sort of code! Let me know how you think I could apply the fixes I am looking to patch in!

Thank you!
One more is never enough ;)

RedPanther
Posts: 39
Joined: Thu Sep 12, 2019 9:20 pm

Re: My first Python app--Age Calculator(need suggestions!)

Mon Oct 21, 2019 1:28 am

I would also like to force the app to pull current Date information(month, day, year) from the OS. That way the end user doesn’t have to program the current date every day.

Another version of this app would feature programming both dates yourself to determine the difference between two dates( from 8-12-96 to 12-15-99 there is a difference of 3 years, 4 months, and 3 days). But that will be once I finish my current app.
One more is never enough ;)

User avatar
Paeryn
Posts: 2707
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: My first Python app--Age Calculator(need suggestions!)

Mon Oct 21, 2019 2:28 am

The datetime module deals with dates and times which you can use to get the date (amongst other things), e.g.

Code: Select all

import datetime

today = datetime.date.today()
day = today.day
month = today.month
year = today.year
print('Today's day is', day)
print('The month is', month)
print('The year is', year)
A random page with a tutorial on datetime : https://www.listendata.com/2019/07/how- ... n.html?m=1
She who travels light — forgot something.

User avatar
joelostinspace
Posts: 20
Joined: Sat Aug 10, 2019 2:51 pm
Location: Earth

Re: My first Python app--Age Calculator(need suggestions!)

Mon Oct 21, 2019 2:50 am

input always makes your program more dynamic:

Code: Select all

bm= input('Enter your birth month: ')
bd= input('Enter your birh day: ')
by= input('Enter your birth year: ')
print('month: {0} day: {1} year: {2}'.format(bm,bd,by))
bm bd and by are all strings convert to integer

Code: Select all

int(bm)

I would rather live in a world where my life is surrounded by mystery than a world so small that my mind could comprehend it.


--- Harry Emerson Fosdick

hippy
Posts: 6104
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: My first Python app--Age Calculator(need suggestions!)

Mon Oct 21, 2019 12:47 pm

RedPanther wrote:
Mon Oct 21, 2019 1:06 am
While my app works great for its originally intended purpose, I would like to add more to it. If you have any suggestions, please help!
One thing I can think of which should also help you with your adventures in programming would be to add astrological signs.

Basic western star signs are fairly easy, being fixed-date based, but get more complicated when planetary alignment comes into play; for example "Virgo with Pluto rising".

Similarly Chinese star signs; animal and elemental.

You can extend that to give a report of what their star sign suggests about the person.

Biorhythm status is something which could also be added. Again with an extended explanation.

You could also add a list of famous people they share their birthday with, though who 'famous people' are can depend on where they have lived.

And there's an interesting issue; what if their birth date was for a different part of the world ?

Adding some information which the user wouldn't know makes it more likely they will be impressed than just being told their age, which most will probably already know.

RedPanther
Posts: 39
Joined: Thu Sep 12, 2019 9:20 pm

Re: My first Python app--Age Calculator(need suggestions!)

Mon Oct 21, 2019 2:01 pm

Pearyn:

Thanks for the quick input about date & time! Exactly what I was looking to add in!

Joelostinspace:

Thanks for the help with making it interactive! The program will be able to run like a regular app now!

Hippy:

Your suggestion perfectly suits your name and I like it! That would take a lot of time and research to code everything in like that for each day of the year. Is there a way I could do like some apps, and hyperlink to another page online for “fun facts about this day”? Maybe to help keep the app cleaner. Or would you suggest having this all built into the app? Which would offer a more immediate prompt of “fun facts” rather than having to follow a link if you are ever without internet. Well, I think I answered my own question there. Maybe trying to incorporate a network detection service when the app opens, to activate hyperlinks for online access, or fallback to internally coded information if there’s no internet access detected. Something like pinging the Google server and waiting for a response?

These are all great tips! I’ll have to get messing around to work out all of the glitches in the app and incorporate everything else. Thank you all!
One more is never enough ;)

Return to “Python”