+ 1

How can I create an age calculating app with python?

Since yesterday I have been struggling in creating an app that can calculate age.Normally to determine the age of an individual,you can just substract the present year(e.g 2020)by the year the individual was born. So I try coding in Python like this: print('Age Calculator') x=2020 y=input('Please kindly enter your birth year: ) >>>Please kindly enter your birth year:2000 x - y Type error Normally x is 2020 and I supposely program 'y' to be the birth year of a person depending on what the year is typed.(e.g I chose to pick year 2000) So x - y Should be 2020 - 2000 equal to 20 But something went wrong. Plz any suggestions

21st Mar 2020, 8:45 AM
Tobby
Tobby - avatar
4 Answers
+ 2
Oki Toyin The error is that you are taking an input in type string, it should be integer or float to get subtracted by 2020, you can't subtract 2020 from "2019" because both are different types, one is a number one is a word. So, in addition to input("Enter an year") type int at the beginning like int(input("Enter age:))
21st Mar 2020, 8:51 AM
maf
maf - avatar
+ 1
Can you please send the code?
21st Mar 2020, 8:46 AM
Taranjeet
Taranjeet - avatar
+ 1
21st Mar 2020, 8:50 AM
Tobby
Tobby - avatar
+ 1
Thanks@maf
21st Mar 2020, 8:56 AM
Tobby
Tobby - avatar