bug in my code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: bug in my code (/thread-1906.html) |
bug in my code - sunnysude - Feb-03-2017 when i run the code on my laptop it runs fine. but when i try to submit online it detects a bug with online Type Error . what can i do to correct the code. the code is suppose to check for isogram, raise a typeerror if non string input is supplied and also return a false if an empty string is entered . my code def is_isogram (saw): cat = str(saw) while True: if len(cat) < 1 : return ("(argument, False)") elif not cat.isalpha(): raise TypeError ("\'Argument should be a string'") else: for me in cat: cat = cat.lower() if cat.count(me) > 1: return (cat, False) return (cat, True) RE: bug in my code - nilamo - Feb-03-2017 Related: https://python-forum.io/Thread-writing-a-function-for-isogram (Feb-03-2017, 08:42 PM)sunnysude Wrote:raise TypeError ("\'Argument should be a string'") Why does your string have a backslash in it? Also, why does your error nest an extra pair of quotes within it? I mean, if the error you're getting is the TypeError, you should probably look at your type error to see what you're doing :P RE: bug in my code - Ofnuts - Feb-03-2017 It all depends where you get saw from. If you are using a wrong encoding, bytes for accented characters could be converted to the wrong characters.Also,
RE: bug in my code - sunnysude - Feb-05-2017 (Feb-03-2017, 09:12 PM)Ofnuts Wrote: It all depends where you get have changed the code and removed the quotes and back slash but am still getting the error how can i remove the bug . the one u found with the uppercase ? Quote:def is_isogram (word): RE: bug in my code - Larz60+ - Feb-05-2017 Please add code tags so indentation is preserved (and because it's a forum rule) RE: bug in my code - sunnysude - Feb-05-2017 (Feb-03-2017, 09:05 PM)nilamo Wrote: Related: https://python-forum.io/Thread-writing-a-function-for-isogramhave removed the backlash but am still getting the error (Feb-05-2017, 12:29 PM)Larz60+ Wrote: Please add code tags so indentation is preserved (and because it's a forum rule) ok was not aware . but have done that now RE: bug in my code - sparkz_alot - Feb-05-2017 You are getting an error, because you are telling Python to generate an error, so Python says "okee dokee here's an error" If you don't want that, try something like: elif not cat.isalpha(): print("not alpha") breakJust a matter of semantics, but your response "Argument should be a string", is not really accurate, since at the beginning of your function you are converting every thing to a string. RE: bug in my code - sunnysude - Feb-05-2017 (Feb-05-2017, 02:58 PM)sparkz_alot Wrote: You are getting an error, because you are telling Python to generate an error, so Python says "okee dokee here's an error" according to the assignment question am suppose to raise a type error here is the full question Write a program that checks if a word supplied as the argument is an Isogram. An Isogram is a word in which no letter occurs more than once. Create a method called is_isogram that takes one argument, a word to test if it's an isogram. This method should return a tuple of the word and a boolean indicating whether it is an isogram. If the argument supplied is an empty string, return the argument and False: (argument, False). If the argument supplied is not a string, raise a TypeError with the message 'Argument should be a string'. |