Guess any age

jasimp 0 Tallied Votes 156 Views Share

All this snippet does is asks you for some information and then uses it and some math to guess your age. Pretty simple but I have to start somewhere.

import time
a = input("How many days a week would you like to eat chocolate?  ")
b = input("Have you had your birthday yet this year(1=yes 0=no)?  ")
d = input("Enter your Date of Birth(year only) ")
if b == 1:
	e = 1757
elif b == 0:
	e = 1756
c = ((a*2+5)*50+e)-d
print "This is the first step. Muiltiplying your number by 2 which =", a*2
time.sleep(3)
print "Now we add five to your number which =", (a*2)+5
time.sleep(3)
print "Now we mulitply your number by 50 which =", (a*2+5)*50
time.sleep(3)
print "Now we add 1757 if you have had your birthday or 1756 if you have not =", (a*2+5)*50+e
time.sleep(3)
print "Lastly we subtract your year of birth from your number which =",c 
time.sleep(3)

print "If you notice your number now is split into two parts. The first part is how     many times you would like to eat chocolate a week and the second is your age."
raw_input("Hit Enter to Quit")
jasimp 427 Senior Poster Featured Poster

this will only work in the year of 2007 and you will have to very slightly modify it for the new year.

Dani 4,329 The Queen of DaniWeb Administrator Featured Poster Premium Member

In PHP, the time() function gets the current system time. Perhaps there is a Python equivalent that fetches the current year according to the system time? It would be a nice next step as you learn and improve your Python.

majestic0110 187 Nearly a Posting Virtuoso

Very nice, I don't know much about Python (at all in fact) and am trying to figure out why it won't work in this year and where it needs modifying but haven't figured it out yet. Will let you know when I do lol. I made a similar application myself when I was learning C#, these 'guess my age' programs are a good starting point for people who are new to a language. Thanks for the Snippet!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.