Also: Briefly describe problem 22 Show us what you did to test the program It would be better to test for integer before doing a numeric comparison There is no need ever to compare a boolean expression to true or false. All you need is either if condition or if not condition. A good short cut for a range test is if 0<= x <= 6: It is not necessary to surround a condition with parentheses. Your code will be simpler if you initially set Bueller to true, then change it to false as needed. Please excuse my spelling as I am dictating this. Who would have thought so many comments could come from such a simple piece of code. On Oct 16, 2015 7:17 PM, "Alan Gauld" <alan.ga...@btinternet.com> wrote:
> On 16/10/15 23:31, zak nelson wrote: > >> I don't understand why this program is said to be "not defined" when I >> test >> it. >> > > In future please be more precise in describing the problem, > and that means including the full error message in the post. > It contains a lot of useful information. > > I'm guessing it doesn't say that the program is not defined > but it says the name buler is not defined? Is that correct? > > Notice the spelling? > Now look at your code > > def problem22(aList): >> length=len(aList) >> if (length>6): >> bueler=False >> else: >> bueler=True >> for i in aList: >> if(i < 0 and i > 6)==False: >> bueler=False >> else: >> buler=True >> if type(i)!=("integer"): >> bueler=False >> else: >> bueler=True >> return bueler >> > > But there are a couple of other issues in there too. > Specifically this line: > > if(i < 0 and i > 6)==False: > > The bit in parentheses can never be true because i can > never be both <0 and >6 at the same time. So the if > statement is always true and the next line is always > executed. > > Also the line > > if type(i)!=("integer"): > > Will never be true because the string 'integer' is not a type. > You should use the type name: > > if type(i) != int > > or compare to the type of a known value: > > if type(i) != type(5): > > In the case of an int the first one would be better. > A final refinement is that for these kinds of comparisons > it probably reads better to use is/is not rather > than the ==/!= symbols, so: > > if type(i) is not int: > > HTH > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor