+ 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
4 Respuestas
+ 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:))
+ 1
Can you please send the code?
+ 1
Ok@Taranjeet
+ 1
Thanks@maf