0

Hey I'm having an issue getting the last bit of my code to run. I am unable to get the values at the end and believe it may have to do with my formatting, although I'm not entirely sure. Instead of stabbing in the dark I thought I'd ask around here as the fastest way to improve is with help from the more experienced. I'm new, and not seasoned. Haven't been programming for a full 2 months yet.

import math def month(): month = input(' # of month born ') if month == '1': print ("January") return "January" elif month == '2': print ("February") return "February" elif month == '3': print ("March") return "March" elif month == '4': print ("April") return "April" elif month == '5': print ("May") return "May" elif month == '6': print("June") return ("June") elif month == '7': print ("July") return "July" elif month == '8': print("August") return "August" elif month == '9': print("september") return "September" elif month == '10': print("October") return "October" elif month == '11': print ("November") return "November" elif month == '12': return "December" print ("December") else: return month() month() print('day born') day=input(' input day # ') print ('{}'.format (day)) if month==1 and day<20: print ('Capricorn') elif month ==1 and day>22: print ('aquarius') 

It does everything fine except return aquarious or capricorn. How may I format it correctly so it prints these values?

1 Answer 1

1

You run the function month(), right after the definition of it, but you do not store the return value. You should do this:

m = month() if m == "October": # ... 

But instead, you're comparing the function month to 1, which will result to False.

def month(): pass # month is a function month == 1 # is month equal to 1? no! this is False 

Also, the function month actually returns string by your design, so you should not compare it to 1, but to "January", for example. Also, there's a very handy builtin package for this, you can use datetime here, see https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior.

In [3]: import datetime In [4]: datetime.datetime(2000, 1, 1).strftime('%B') Out[4]: 'January' In [5]: datetime.datetime(2000, 12, 1).strftime('%B') Out[5]: 'December' 

So in a function:

def convert_number_to_month_name(i): return datetime.datetime(2000, i, 1).strftime('%B') 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.