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)
1/24/2021 11:23:47 PMᙢᖇ.ᚪ ᚱ ع ℰ 爪 Ꭿ ກ
5 AnswersNew Answer
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')
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!
Error in the count function . It counts all the same characters in a string, not the ones standing next to each other.
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")