+ 1

Find the error

Just give me the clue and error in deja vu task in code coach. I will try myself. Task: If I give same characters multiple times as input then it should print Deja vu else Unique p = input() i = 0 l = 0 for i in range(len(p)): j = i+1 if p[i]==p[j:]: l = l+1 else: pass if l>0: print("Deja Vu") if l==0: print("Unique")

13th Jul 2020, 7:03 AM
Lokesh Amaravathi
Lokesh Amaravathi - avatar
5 Respuestas
+ 2
if p[i]==p[j:]: This compares with a charecter p[i] with remaining all charecters list p[j:], not individually single charecter.. Need a single change in this. Edit: Lokesh Amaravathi is it stil error..? not resovled..?
13th Jul 2020, 7:17 AM
Jayakrishna 🇮🇳
0
just take the first character in the string and compare them with a for loop and use a boolean to control the correctness of the statement unique = True text = input() firstChar = text[0] for i in text: if i != firstChar: print(“Unique”) unique = False break if unique: print(“Deja Vu”) edit: if it is a function you will not need the boolean and can just return at the break statement and if it will not break it will print deja vu
14th Jul 2020, 1:06 AM
Arda Atıcı
Arda Atıcı - avatar
0
Arda Atıcı there was an error , it's only giving unique as output
14th Jul 2020, 3:46 AM
Lokesh Amaravathi
Lokesh Amaravathi - avatar
0
https://code.sololearn.com/cB9V5K2T2trn/?ref=app works for me keep in mind it is case sensitive
14th Jul 2020, 11:55 AM
Arda Atıcı
Arda Atıcı - avatar
0
https://code.sololearn.com/cO0wbAdZ8Xfd/?ref=app and this is a better way of doing it with a custum function
14th Jul 2020, 12:02 PM
Arda Atıcı
Arda Atıcı - avatar