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

24th Jan 2021, 11:23 PM
Kovalov Evgen
Kovalov Evgen - avatar
7 Antworten
+ 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')
9th May 2021, 4:22 PM
Jobayer Ahmed
Jobayer Ahmed - avatar
+ 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!
25th Jan 2021, 12:38 AM
noteve
noteve - avatar
+ 1
Error in the count function . It counts all the same characters in a string, not the ones standing next to each other.
24th Jan 2021, 11:32 PM
Эдуард
Эдуард - avatar
31st Mar 2021, 12:27 PM
Naga Raju K
+ 1
https://code.sololearn.com/cP67DpsbB60W/?ref=app
14th Jul 2022, 4:13 PM
Joe Davies
Joe Davies - avatar
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")
26th Dec 2021, 4:26 PM
Giacomo Cicala
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.
24th Oct 2022, 12:43 AM
Dragon RB
Dragon RB - avatar