I'm trying to write a simple if-statement that depends on a set of conditions (the occurences in a list being 0) however I have encountered bugs when two of my conditions are both 0, only one of the statements is displayed.
if let1 == 0:
print("Segmentation unavailable as corpus does not contain the following letter ",a, "\n")
elif let2 == 0:
print("Segmentation unavailable as corpus does not contain the following letter ",b, "\n")
elif let3 == 0:
print("Segmentation unavailable as corpus does not contain the following letter ",c, "\n")
I've tried using or statements but am unable to produce the desired output informing the user that one, two or three of their inputs may not be in the body of text used in the rest of my program.
Apologies for the lack of succint terminology as I'm very new to programming.
Thanks
EDIT: Thank you for the replies but I should have given the full function...
def segment_sequence(mycorpus, letter1, letter2, letter3):
corpus_string = "".join(mycorpus)
a = letter1
b = letter2
c = letter3
d = a + b
e = b + c
let1 = corpus_string.count(a)
let2 = corpus_string.count(b)
let3 = corpus_string.count(c)
let1let2 = corpus_string.count(d)
let2let3 = corpus_string.count(e)
print(let1,let2,let3)
if let1 == 0:
print("Segmentation unavailable as corpus does not contain the following letter ",a, "\n")
if let2 == 0:
print("Segmentation unavailable as corpus does not contain the following letter ",b, "\n")
if let3 == 0:
print("Segmentation unavailable as corpus does not contain the following letter ",c, "\n")
break
else:
trans_prob1 = let1let2/let1
trans_prob2 = let2let3/let2
if trans_prob1 > trans_prob2:
print('Here is the proposed boundary given the training corpus:\n')
print('Proposed end of one word:' ,d,'\n')
print('Proposed beginning of new word:' ,c,'\n')
elif trans_prob2 > trans_prob1:
print('Here is the proposed boundary given the training corpus:\n')
print('Proposed end of one word: ',e,'\n')
print('Proposed beginning of new word: ',a,'\n')
elif trans_prob1 == trans_prob2:
print('Both ',d,' and ',e,' are equally possible word endings')
return()
the problem with using if instead of elif is that it doesn't break and I then get errors for division by 0. I'm not looking for anything too complicated just a simple and accurate user error message.
Thank you again
Aucun commentaire:
Enregistrer un commentaire