oops python如果elfi错误

时间:2017-10-06 16:29:53

标签: python oop

   def book_search(self,match):
        self.match = match
        for inum in range(len(self.mybooksinventory)):
            if (self.match == self.mybooksinventory[inum]['name']):
               print ("Congrats You Book is available")
               self.book_details_print(inum)
            elif (self.match == self.mybooksinventory[inum]['stuclass']):
               print ("Congrats You Book is available")
               self.book_details_print(inum)
            elif (self.match == self.mybooksinventory[inum]['subject']):
               print ("Congrats You Book is available")
               self.book_details_print(inum)
            else:
               print ("+" * 55)
               print ("Book You are looking for is not available")
[bookstore]# ./Book.py
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Book You are looking for is not available
Congrats You Book is available
*******************************************************
Name: India
for student of class: Arts
Subject: History
Language of Book is: English
[root@su01897 bookstore]#

问题:当我能够搜索书籍时,这是正确的......那么为什么我的程序也会说“你正在寻找的书籍”是不可用的#34;来自else循环... 如果条件为真则为什么它会进入else循环。

1 个答案:

答案 0 :(得分:0)

在if / elif。

成功回复后添加root@kali:~/rubyprograms# irb irb(main):001:0> words = ["house", "dog", "cat", "man", "girl"] => ["house", "dog", "cat", "man", "girl"] irb(main):002:0> phrases = ["I have a house", "I am a dog", "I am man"] => ["I have a house", "I am a dog", "I am man"] irb(main):003:0> irb(main):004:0* words.select { |word| phrases.any? { |phrase| phrase.include? word } } => ["house", "dog", "man"]
break