- 2
Write a program that checks if a word supplied as the argument is an Isogram. An Isogram is a word that a each letter occurs onc
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'.
8 Réponses
+ 2
# This function returns a boolean and prints a tuple
# If you want to return both tuple and boolean you could
# return them in a list but by the name of function it should return bool only
def is_isogram(word):
word_tuple = ()
# If greater than zero
if(len(word) > 0):
# Put every character in tuple
for c in word:
word_tuple += (c,)
# Set data structure doesnt accept any duplicates
test_set = set(word_tuple)
# If they are same length, there is no doubles, it is isogram!
if (len(test_set) == len(word_tuple)):
print(word_tuple)
return True
else:
print(word_tuple)
return False
else:
return False #Returns false if length of word < 0
+ 1
# Bad way in my opinion, but does the job, I think my other solution is better,
# although it doesn't really matter for short words...
def is_isogram_2(word):
word_tuple = ()
if(len(word) > 0):
# Put every character in tuple
for c in word:
word_tuple += (c,)
#Test every char with every other char
for i in range(1, len(word_tuple)):
counter = 0
test_char = word_tuple[i]
for c in word:
if test_char == c:
counter += 1
if counter > 1:
return False
counter = 0
return True;
else:
return False;
+ 1
And, next time WRITE YOUR CODE THAT TRIES TO SOLVE IT.
+ 1
I want you all to know that I'm new to programming a. I have some home assessments with a deadline to meet... and I don't know how to code and understanding my text books without a real teacher has not been easy.
+ 1
@timothy ukaegbu write MIT 6.00SC on youtube. In description of firat lecture you will find link for whole course materials too. great teachers theg are. good luck
0
what if the expected result is ("abolishment" true)
- 1
abolishment