-1

I am struggling with getting the right output for my code. The code keeps giving me the wrong state as my output, what am I doing wrong?

def whatState(cityName):
    if cityName == "dallas" or "austin" or "houston" or "ft worth" or "el paso":
        stateName = "Texas"
    elif cityName == "sacramento" or "san francisco" or "los angeles" or "san diego":
        stateName = "California"
    elif cityName == "miami" or "west palm beach" or "orlando" or "key west" or "tallahassee":
        stateName = "Florida"
    elif cityName == "chicago" or "naperville" or "peoria" or "evanston" or "rockford":
        stateName = "Illinois"

    return stateName

When I try testing my code with chicago I'm getting Texas as my output, when I should be getting Illinois

Thank you in advance!

1 Answers1

0

The easiest way would be:

def stateName(cityName):
    if cityName in ["dallas", "austin", "houston", "ft worth", "el paso"]:
        stateName = "Texas"
    elif cityName in... 

    return stateName 
Zoe
  • 27,060
  • 21
  • 118
  • 148
Andres Silva
  • 874
  • 1
  • 7
  • 26