Indentation error


# season from month and day
season = ""

#month name as a string
month_name = input ("Enter the name of the month: ")


day = ""
if month_name == "march" or "june" or "september" or "december":
    day = int(input ("Enter the day: "))

else:


#conditions for spring season and dates
if month_name == "march" and  day >= 20:
    print (season = "spring")
elif month_name == "march" and  day <= 31:
    print (season = "spring")
elif month_name == "april" :
    print (season = "spring")
elif month_name == "may" :
    print (season = "spring")
elif month_name == "june" and day >= 1  :
    print (season = "spring")
elif month_name == "june" and day <= 20 :
    print (season = "spring")

#conditions for summer season and dates

elif month_name == "june" and day >= 21:
    print (season = "summer")
elif month_name == "june" and day <= 30 :
    print (season = "summer")
elif month_name == "july" :
    print (season = "summer")
elif month_name = "august" :
    print (season = "summer")
elif month_name == "september" and day >= 1 :
    print (season = "summer")
elif month_name == "september" and day <= 21 :
    print (season = "summer")



#conditions for fall season and dates
elif month_name == "september" and day >= 22 :
    print (season = "fall")
elif month_name == "september" and day <= 30 :
    print (season = "fall")
elif month_name == "november" :
    print (season = "fall")
elif month_name == "december" :
    print (season = "fall")

#conditions for winter  season and dates

elif month_name == "december" and day >= 22 :
    print(season = "winter")
elif month_name == "december"  and day <= 31:
    print(season = "winter")
elif month_name == "january"  :
    print (season = "winter")
elif month_name = "february"  :
    print (season = "winter")
elif month_name == "march" and day >= 1 :
    print(season = "winter")
elif month_name == "march" and day <= 19:
    print(season = "winter")


when l run the code it tells me here it needs an indentation ,but after doing that nothing is solved and l don’t understand why it is saying that

Hello! Could you be more specific in terms of what your error actually is?

Notice how you have an empty else block above those lines:

An else needs at least one line in it, otherwise code after it which is not indented to be part of it will throw an error.

I wanted after the else the code to just carry on

Well, you’ll still have to indent everything correctly. If you don’t actually want the else, as in, you want the rest of the code regardless of this condition:

What happens if you remove the else?

after removing else l get another error

I don’t know why this is wrong

You can’t assign something to a variable inside a print statement.

Thank you that was a learning point

1 Like