Thread: Code Help!

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Code Help!


    I'm making a program that tells the user how old they are in years, minutes, seconds and how much longer they have left to live in minutes asuming they'll live to 85. But it comes as Error, can someone help me find it?


    Code:
    #This program will ask for the user's First and Last name as well as their age.
    print ('Hello, what is your first name?')
    firstName=input()
    print ('Hello ' + firstName + ', what is your last name?')
    lastName=input()
    print ('How old are you?')
    ageYears=input()
    ageMinutes=ageYears*525600
    ageSeconds=ageMinutes*60
    ageLeft=(85-ageYears)*525600
    print(firstName + ' ' + lastName + ', welcome to the program. You are ' + ageYears + ' years old, and have lived for approximately ' + ageMinutes + ' minutes. You have approximately ' + ageLeft + ' minutes left in your life if you live to be 85. Enjoy the rest of your life, ' + firstName + ', as it will be over in approximately ' + ageSeconds + ' seconds.')
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,843
    Rep Power
    480
    You ran your program in python 3 and didn't bother to convert string returned from input() to an integer.
    These statements produced some long strings! (Not integers as you expected.)

    ageMinutes=ageYears*525600
    ageSeconds=ageMinutes*60

    >>> 'hi'*3
    'hihihi'
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Ohh, I see now, thanks for the help!

IMN logo majestic logo threadwatch logo seochat tools logo