0
Please tell and solve the bug in program!
Why it's returning wrong value if i input a word "cerebral" as input.. x=input() for i in x: if x.count(i)>1: print("false") break else: print("true") break
3 Answers
+ 4
Code Shooter
The error is here:when The `break` statement is causing the loop to terminate after checking only the first character of the input string.
To fix the bug:
move the `break` statement outside of the `else` block.
See this modified code..
https://code.sololearn.com/ckuNixAbDSGS/?ref=app
+ 2
Code Shooter
You've got the right idea to loop through each letter in string x and breaking from the loop if ANY letter occurs more than once. But for a word to be an isogram, ALL the letters must occur only once. The `else` clause will run when the first single-occuring letter is encountered (in this case 'c'), and the `break` exits the loop early after printing the wrong output.
This is my fix:
x = input()
is_isogram = 'true'
for i in x:
if x.count(i) > 1:
is_isogram = 'false'
break
print(is_isogram)
0
Your pseudocode is good, your input is clear. Placing the "break" after print is resulting to a bug in your code making it not to run. Try removing it