I'm working on a very simple problem, but I had some problems.
What I want to write is a function (using the for loop) that veifies if the string put in input is composed by the following letters: a, b, c, and d. If the string contains a letter different from a,b,c or d, the program should give an error message. If the string contains just 1,2, or 3 of the 4 mentioned letters, it will be correct.
- The string
'abbbbbcd'will be correct. - The string
'ab'will be correct. - The string
'ghjja'will be Incorrect. - The sting
'aaabbbcccff'will be Incorrect.
This is my current version of the code:
def string(f):
for i in range(len(f)):
if f[i]!='a' or f[i]!='b' or f[i]!='c' or f[i]!=d':
print('error')
else:
print('ok')