Bottom Page

• 1 Vote(s) - 5 Average
• 1
• 2
• 3
• 4
• 5
 Calculating what year it is when you are 100 years old dankim9000 Unladen Swallow Posts: 2 Threads: 1 Joined: Apr 2017 Reputation: 0 Likes received: 0 #1 Apr-26-2017, 07:55 PM I'm trying to figure out how to get the program to calculate what year it is when the user is 100 years old. The error that it gives me is: Traceback (most recent call last): TypeError: unsupported operand type(s) for -: 'int' and 'str' ```[code] print("The date is as follows:")    import datetime    now = datetime.datetime.now()    print (now.year, now.month, now.day)    name = input("Hi. Please enter your name: ")    print("Hello", name)    age = input("Please enter your age: ")    print("You are going to be age 100 on the year", (now.year-age+100))[/code] ``` volcano63 Verb Conjugator Posts: 564 Threads: 6 Joined: Apr 2017 Reputation: 25 Likes received: 99 #2 Apr-26-2017, 08:00 PM `input` returns string, you have to convert it to integer before calculation nilamo likes this post Test everything in a Python shell (iPython, Azure Notebook, etc.) Someone gave you an advice you liked? Test it - maybe the advice was actually bad. Someone gave you an advice you think is bad? Test it before arguing - maybe it was good. You posted a claim that something you did not test works? Be prepared to eat your hat. dankim9000 Unladen Swallow Posts: 2 Threads: 1 Joined: Apr 2017 Reputation: 0 Likes received: 0 #3 Apr-26-2017, 08:03 PM (Apr-26-2017, 08:00 PM)volcano63 Wrote: `input` returns string, you have to convert it to integer before calculation Thank you... I can't believe I didn't see that -_- « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post 'Age' categorical (years -months -days ) to numeric Smiling29 4 344 Oct-17-2019, 05:26 PM Last Post: Smiling29 Create a monthly mean column in multiple years fyec 1 753 Jun-21-2018, 03:57 AM Last Post: scidam Replacing missing years in the dataframe sangeethasivakumar 0 682 Mar-17-2018, 06:31 AM Last Post: sangeethasivakumar Creating folders dynamically with year/month/date sritsv 0 2,836 Oct-16-2017, 03:44 PM Last Post: sritsv Leap Year MartinEvtimov 14 11,297 Mar-10-2017, 01:46 AM Last Post: Larz60+ leap year program issue jashajmera 3 1,603 Feb-04-2017, 11:51 AM Last Post: ichabod801 Logic to convert an integer to YEAR / MONTH hugobaur 9 2,979 Oct-18-2016, 11:58 AM Last Post: hugobaur

Forum Jump:

Users browsing this thread: 1 Guest(s)