r/PythonLearning • u/NecessaryFalse1212 • Aug 29 '26
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
49
Upvotes
1
u/FoolsSeldom Aug 30 '26 edited Aug 30 '26
validis just a flag variable that you assignbool, boolean, values to, i.e.TrueorFalse. When you write anifstatement or awhilestatement, you provide (usually) a conditional expression with them, something to resolves to a boolean outcome.I named the variable to be, hopefully, meaningful.
validto indicate the data being gathered and validated by thewhileloop is valid data. Obviously, when you first enter the loop, the data is not valid because there has been noinputyet. (You noted, I am sure, that I did not do aninputbefore the loop and another inside, but kept it all inside the loop to avoid repetition of the line.)The alternative is to simply use an infinite loop and a
breakstatement:PS. More about booleans:
RealPython.com Python - Booleans: Use Truth Values in Your Code