Where am i wrong?

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
Question - A word is called a good word if all letters of the word are distinct. That is, all the letters of the word are different from each other letter. Else the word is called as a bad word!

<In what way does your code behave incorrectly? Include ALL error messages.>

a = input('Enter a word')
flag=0
a=str(a)
v = len(a)

for i in range(v):
    b = a[i]
    j=i+1
    for j in range(v):
        if(b==a[j]):
            flag=1
            break

if(flag==0):
    print('Good')
else:
    print('Bad')

<What do you expect to happen instead?>
Enter Rajesh - It should output Good but it gives bad as output. Please help!

```python

Replace this line with your code.

<do not remove the three backticks above>

a is already a string.

>>> a = input('Enter a word')
Enter a wordthis
>>> type(a)
<class 'str'>
>>> 

When comparing two values in the same iterable, stop the outer loop 1 before the inner loop.

>>> def check_word(a):
    v = len(a)
    for i in range(v-1):
        for j in range(i+1, v):
            if a[i] == a[j]: return False
    return True

>>> check_word('supper')
False
>>> check_word('tuple')
True
>>> 

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