Isogram problem

The codes below is to address this problem: 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.

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’

Help check what is wrong with the codes below:
import unittest
class IsogramTestCases(TestCase):
def test_checks_for_isograms(self):
word = ‘halo’
self.assertEqual(
is_isogram(word),
(word, True),
msg=“Isogram word, ‘{}’ not detected correctly”.format(word)
)

def test_returns_false_for_nonisograms(self):
word = ‘alphabet’
self.assertEqual(
is_isogram(word),
(word, False),
msg=“Non isogram word, ‘{}’ falsely detected”.format(word)
)

def test_it_only_accepts_strings(self):
with self.assertRaises(TypeError) as context:
is_isogram(2)
self.assertEqual(
‘Argument should be a string’,
context.exception.message,
‘String inputs allowed only’
)

Is this a homework assignment? Does the professor allow reaching out for help?

In a simple proof of concept, here is the output; running in Python 3:

>>> is_isogram('word')
('word', True)
>>> is_isogram('swords')
('swords', False)
>>> is_isogram('w0rd')
Traceback (most recent call last):
  File "<pyshell#54>", line 1, in <module>
    is_isogram('w0rd')
  File "<pyshell#51>", line 3, in is_isogram
    if not word.isalpha(): raise ValueError
ValueError
>>> is_isogram(42)
Traceback (most recent call last):
  File "<pyshell#55>", line 1, in <module>
    is_isogram(42)
  File "<pyshell#51>", line 2, in is_isogram
    if not isinstance(word, str): raise TypeError
TypeError
>>> 

It is not using unittest, that’s still on you. If you actually have a question or two, that will help us to advise you. As it stands now all we can do is watch. It would be improper to critique or debug your code, given the assumption this is an assignment. Once you solve it, let us know.

Update

Here is the unit test result of my is_isogram function:

======== RESTART: D:/Python35/practice/is_isogram_unittest.py ========
test_checks_for_isograms (__main__.IsogramTestCases) ... ok
test_it_only_accepts_strings (__main__.IsogramTestCases) ... ok
test_returns_false_for_nonisograms (__main__.IsogramTestCases) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.023s

OK
>>> 

Can we have a look at your is_isogram function?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.