出于某种原因,我所有的"如果"和" elif""无论什么
,都会回来nyornj = raw_input("select ny or nj please")
newyork="NY" or "nj"
newjersey="NJ" or "nj"
if nyornj==newyork:
print "New York was input"
if nyornj==newjersey:
print "New Jersey was input"
似乎没有什么工作,任何想法为什么这总会回归真实?
答案 0 :(得分:0)
使用str.lower()转换为全部小写然后进行比较,而不是与两个不同的值进行比较。
nyornj = raw_input("select ny or nj please")
newyork="ny"
newjersey="nj"
if nyornj.lower()==newyork:
print "New York was input"
if nyornj.lower()==newjersey:
print "New Jersey was input"