0
I am having a problem in code coach deja vu
Here is my code: a= input() b = list(a) c=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] for i in c: if b.count(i)>=2: print ("Deja Vu") break If b.count(i) <2: print ("Unique") The problem is that i dont the second if to execute unless it's true for all items and i dint how to do it please explain kindly, i dont want just codes that may i want explanations. Thank you
3 Answers
+ 2
Your code if parts gets tested for every iteration. 1st if works well but your 2nd if needed to get execute only when 1st if fails. So use for-else loop construct instead of for loop. Or else find in loop if any letter is repeated in input string .. If repeated then set a flag to true and break loop. Now depending on this flag, output by if-else.
And also instead of testing for all charecters, you only need to test charecter of input so instead of using list c, use list b in : for i in c => for i in b :
Hooe it helps...
+ 1
str=input()
count_2=0
for i in range(0,len(str)):
count = 0
for j in range(0,len(str)):
if str[i]==str[j]:
count_2+=1
if count_2== len(str):
print("Unique")
else:
print("Deja Vu")
+ 1
word = input()
for i in word:
if bla bla bla:
print("deja vu")
else:
print("unique")