+ 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")
5 Answers
+ 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..?
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
0
Arda Atıcı there was an error , it's only giving unique as output
0
https://code.sololearn.com/cB9V5K2T2trn/?ref=app
works for me
keep in mind it is case sensitive
0
https://code.sololearn.com/cO0wbAdZ8Xfd/?ref=app
and this is a better way of doing it with a custum function