+ 2
Deja Vu task
https://www.sololearn.com/coach/54?ref=app I have problems in Deja Vu task. No need to give me your codes, just correct mine. Here is my code: x = input() y = list(x) for i in range( len(y) + 1): if y.count([i]) == True: x = ("Deja vu") else: x = ("Unique") print(x)
7 Answers
+ 5
s = input()
c = 0
for l in s:
if s.count(l) > 1:
c = s.count(l)
if c > 1:
print('Deja Vu')
else:
print('Unique')
+ 4
I see several bugs so I'll just list down here since you don't want the entire code.
---( 1 )---
if 1 == True:
This condition is also True as all numbers except 0 is Truthy, and therefore even if the character is Unique, it will print "Deja Vu" because the condition is True.
---( 2 )---
You are only iterating the numbers or the indexes of the string and not the characters of it.
Your program is doing this: [ index ]
It should be like this: list[ index ]
---( 3 )---
There will be also a problem with the for loop as len(list) + 1 will cause an IndexError, so you may want to adjust this one.
---( 4 )---
Once it finds a duplicate character, you may also want to break the loop because you have already found a multiple character.
Because for example, if it detects a mutiple character, it will still iterate upto last character and what if that last character is Unique?
---( 5 )---
Check your spelling...
______________
Hope this helps, if you need more expanation, please feel free to ask. Thanks!
+ 1
Error in the count function . It counts all the same characters in a string, not the ones standing next to each other.
+ 1
https://code.sololearn.com/cP67DpsbB60W/?ref=app
0
sent=input()
x=0
for i in sent:
x +=1
if i in sent[x:]:
print ("Deja Vu")
break
elif i not in sent[x:] and x==len(sent):
print ("Unique")
0
Here is my code:
h = sorted(input())
l = []
o = False
for i in range(-1, len(h)-1):
i+=1
i <= len(h)
if h[i] == h[i-+1]:
l.append("Yes")
else:
l.append("No")
if l[i] == "Yes":
o = True
for q in range(i+1):
q+=1
if l[i] == "Yes" and l[i-q] == False:
o = True
if o is True:
print("Deja Vu")
else:
print("Unique")
This is a little confusing, but this took me a long time to do this.