Having some if/and problems in Python

If anybody can help me I would really appreciate it! I’m working on a little personal project in PyCharm that will take a person’s birthdate and tell them their zodiac sign. I’m trying to use AND, but I think I’m screwing it up because the month is a string and the rest are ints… here’s my code:

def find_sun_sign():
if day > 0 and day < 23 and month == ‘august’:
sun_sign = ‘leo’
return sun_sign

I keep getting this error:

in find_sun_sign
if day > 0 and day < 21 and month == ‘august’:
TypeError: ‘>’ not supported between instances of ‘str’ and ‘int’

Hello! What type of data are you storing in the day variable? If it is a string(remember, anything within "" is a string "0", "string" and "True" are all strings), then you can’t compare an int and string with < or >.

it is an int (a number for day of the month)

Are you sure? Can I see the full code, please?

# Draft of my astro friend

print("What is your birth month?")
month = input()
print("Which day of that month is your birthday?")
day = input()
print("What is your birth year?")
year = input()

month = month.lower()

sun_sign = 'blank'


def find_sun_sign():
  if day > 0 and day < 23 and month == "august":
    sun_sign = "leo"
    return sun_sign

print(find_sun_sign())

The input() function returns a string, so you’ll need to convert in to an integer.

2 Likes

oh duh- thank you so much!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.