Matticus
Matticus

Reputation: 91

Python 3+ Printing which season is determined by user input

I currently am stuck on a Python3 Exercise and I cant seem to find what im doing wrong. Im having to write a program that prompts the user for a month and day, using this algorithm,

if month is 1,2 or 3 season = winter
else if month is 4,5,6 season = spring
else if month is 7,8,9 season = summer
else if month is 10,11,12 season = fall
if month is divisble by 3 and day >= 21
if season is winter, season = spring
else if season is spring, season = summer
else if season is summer, season = fall
else season = winter

This is what my code looks like so far.

month = input("Enter a month: ")
day = input("Enter a day: ")

season = ""

if month == 1 or month == 2 or month == 3:
    season = "Winter"

elif month == 4 or month == 5 or month == 6:
    season = "Spring"

elif month == 7 or month == 8 or month == 9:
    season = "Summer"

elif month == 10 or month == 11 or month == 12:
    season = "Fall"

if month % 3 == 0 and day >= 21:
    if season == "Winter":
        season = "Spring"
elif season == "Spring":
    season = "Summer"
elif season == "Summer":
    season = "Fall"
else:
    season = "Winter"

print("Season is ", season)

Im getting traceback errors after the inputs. Im sure its something very minor that im not catching. Any ideas? I appreciate your time and help.

EDIT: Updated Code

month = int(input("Enter a month: "))
day = int(input("Enter a day: "))

season = ""

if month == 1 or month == 2 or month == 3:
    season = "Winter"

elif month == 4 or month == 5 or month == 6:
    season = "Spring"

elif month == 7 or month == 8 or month == 9:
    season = "Summer"

elif month == 10 or month == 11 or month == 12:
    season = "Fall"

if month % 3 == 0 and day >= 21:
    if season == "Winter":
        season = "Spring"
    elif season == "Spring":
        season = "Summer"
    elif season == "Summer":
        season = "Fall"
    else:
        season = "Winter"

print("Season is ", season)

Upvotes: 0

Views: 2903

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 177800

input() returns the input as a string. Your comparisons are with integers. Use:

month = int(input("Enter a month: "))
day = int(input("Enter a day: "))

Beyond that, the last elifs and else should be indented more.

Upvotes: 2

Related Questions