Where am i wrong?


#1



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!


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')


Enter Rajesh - It should output Good but it gives bad as output. Please help!


Replace this line with your code.


#2

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
>>>

#3

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