0
Isogram Detection Question Python
Hey all. I am working on the code coach Isogram Detection code. I’ve been at it for a while and tried multiple different approaches but can’t seem to get all the test cases to pass. It appears that if the input word’s first character doesn’t repeat it reads it as true regardless of the next characters. Here is a copy of my current coding. Any help would be appreciated. I’m still very new at this. word = input("") for x in word: if word.count(x) > 1: print("false") break else: print("true") break
2 ответов
+ 2
Thanks yall! The firsr solution is out of the box thinking considering what i have learned so far. Python Learner i knew there was some other simple step i was missing. Thank you!
+ 1
Hi Daniel!
That's because of the if-else statements. Generally, if statement is executed if its condition is evaluated true otherwise, else part is executed. Since you used break statement for if, it's checking first character and break the statement if it's true otherwise passes to else.
Inorder to handle this problem, you can use else statement outside loop. So, it will check each character for each iteration.
Here it is your corrected code.
word = input()
for x in word:
if word.count(x) > 1:
print("false")
break
else:
print("true")