https://www.codecademy.com/en/courses/python-beginner-P5YtY/1/6?curriculum_id=4f89dab3d788890003000096如果條件沒有在這是codeacademy
def plane_ride_cost(city):
if city== "Tampa" or "tampa":
return 220
elif city== "Charlotte" or "charlotte":
return 183
elif city== "Pittsburgh" or "pittsburgh":
return 222
elif city== "Los Angeles" or "los angeles":
return 474
任務之一在此代碼,它提交給codeacedemy返回220代碼時正常工作僅是第一個返回值,但它什麼都沒有檢查我猜?
代碼執行爲'城市==(真或真)' - >'city == true'。你不能做'somevalue == val或val或val或','or'首先被解析/執行並簡化爲一個布爾值true/false。你需要'city ==「Tampa」或city ==「tampa」'例如請閱讀:https://docs.python.org/2/reference/expressions.html第5.15節「運算符優先級」 –