我的if语句不适用于python

时间:2018-08-09 21:09:53

标签: python if-statement

我正在尝试制作一个随机句子生成器,当noun2以元音开头时,这段代码应使程序使用“ an”。

import random
noun=['it', 'he', 'she', 'I']
verb=['am', 'is', 'are' ]
noun1=random.choice(noun).capitalize()+" "
verb1=random.choice(verb)+" "
noun2=random.choice(noun)+"."
if noun2[:1]=='a' or 'e' or 'i' or 'o' or 'u':
    asentence=noun1+verb1+'an '+noun2
    print(asentence)
else:
  print('hi')

但是,当我运行程序时,即使noun2以辅音开头,它也始终使用“ an”。

1 个答案:

答案 0 :(得分:1)

Python的工作原理不同于英语。

personId Value createdTime 1991126 19.00 2018-08-05 1991126 16.00 2018-06-15 1991126 18.00 2018-08-06 1991206 32.00 2018-08-02 1991431 6.00 2018-08-06 1991431 7.00 2018-08-07 应该是

Select distinct personId,Value,createdTime
where value>=5 and createdtime>= Dateadd(Day,-7,Getdate()) 

像这样的事情将是一种更好的方法if noun2[:1]=='a' or 'e' or 'i' or 'o' or 'u':

该问题先前已得到解答here。您可以阅读有关逻辑或here的更多信息。