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_ᙢǾሊỢȡΘŬ_
4 AnswersNew Answer
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!
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')
Error in the count function . It counts all the same characters in a string, not the ones standing next to each other.