#!/usr/bin/env python # # computes approximately how many days # you have lived w/o considering partial # or leap years. # # shows the use of loop that is user and count controlled # # example of basic while-loop and if-statement # # written by e.bonakdarian march 2010 # from string import capitalize DAYS_IN_YEAR = 365 MAX_TRIES = 3 ################################################################ def programInfo(): # displays some basic program and usage information # print 'Program will compute approximately how old you are in days' print '(without considering partial or leap years)' print print "You'll have a max of %d entries, or you can quit before then." % MAX_TRIES print ################################################################ def compute_Days(age): # computes the approx number of days return age * DAYS_IN_YEAR ################################################################ def get_ageInfo(): # does the bulk of the work stop = False count = 0 while (not stop) and (count < MAX_TRIES): name = raw_input('What is your name? ') age = input('How old are you (in years)? ') if age >= 1: print ('Dear %s, you are approximately %d days old.' % (capitalize(name), compute_Days(age))) else: print ('\nYou entered "%d" for age.' % age) print ('Please enter a value >= 1') count = count + 1 if count < MAX_TRIES: answer = raw_input('\nEnter "x" to stop, anything else to continue: ') if answer.lower() == 'x': # note use of string functions stop = True else: print '\nYou have reached your limit of %d calculations.' % MAX_TRIES if __name__ == '__main__': programInfo() get_ageInfo() # raw_input('\n to exit')