I am not able to check your code (I get an error message about the usage of urllib, but that might be a difference in Python installations); however, my first guess is that you neglected to take case into account: The page contains the text "Water", not "water", so if you input "water", halal_haram_status will be -1.
As another remark, find() will give the value of the _beginning_ of the match, thus when all goes right, what is returned will contain part of the text sought rather than "Halal" or "Haram" - you will get "er Ha" for water, "anol " for ethanol and "k cho" for pork chops (also, ethanol is the same as alcohol, so I guess it should be haram). On Tue, May 17, 2011 at 5:20 PM, I. Dooba <ido...@gmail.com> wrote: > I'm new to programming and have decided to start with Python following the > advice of experts including Eric S. Raymond. > So far I've learnt quite a lot from this list. > However, I've the following problem. > The program was designed (as part of my practice with Head First > Programming) to check whether an ingredient is Halal or Haram. > I've a simple table online where some ingredients are either halal or > haram. > For example, if the user enters "water" the program is supposed to tell him > that it's halal; > but it's returning ">" and other characters I don't want to see. > What am I doing wrong? > import urllib.request > page = > urllib.request.urlopen("http://halalingredients.theparleyonline.com/") > text = page.read().decode("utf8") > > halal_haram_status = text.find(input("Enter the ingredient: ")) > begin_final_status = halal_haram_status + 3 > end_final_status = begin_final_status + 5 > status = text[begin_final_status:end_final_status] > print(status) > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- André Engels, andreeng...@gmail.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor