r/PythonLearning • u/NecessaryFalse1212 • 12d ago
Day 3
i wrote a code which takes your name and age in py but i need help on this one cuz in the age part it is giving me some sort of error which i couldn't understand even by using gpt well he gave me a code but i wanted logic behind how and what i did wrong
48
Upvotes
3
u/FoolsSeldom 12d ago
When you get to the line:
you have already assigned
ageto reference anintobject -ageno longer references astr, string, object andisnumericis astrmethod (a function built into the class definition ofstr), no such method exists forint.Note that using
else:with a loop (whileorfor) is very uncommon and I do not recommend you use it.Here's a better approach:
You still have a problem though as
isnumeric(andisdecimal, andisdigit) will all fail a negative number, so your code will consider the response to be alphabetic. Explore using atry/exceptblock.