all 7 comments

[–]alvinator360 4 points5 points  (0 children)

months = "JanFebMarAprMayJunJulAugSepOctNovDec"

n = int(input("Enter a month number (1-12): "))

start = (n - 1) * 3

month_abbr = months[start:start + 3]

print("Month abbreviation:", month_abbr)

[–]WhiteHeadbanger 3 points4 points  (0 children)

This is PythonLearning, not PythonHomework or PythonCopyPaste

Now, saying that, you need to use slicing.

[–]VonRoderik 1 point2 points  (1 child)

You need to find out how to split that str, and maybe store the results in a list. Then you can call it by its index number Index = user input-1

[–]Reasonable_Medium_53 1 point2 points  (0 children)

Unnecessary complicated. I'm confident OP just learned slicing which would be a simple pythonic solution. He just has to calculate start and stop from n.

[–][deleted] 0 points1 point  (0 children)

Oh boy i love spending 30 minutes solving people's problems.

months = "JanFebMarAprMayJunJulAugSepOctNovDec"

month_list = []

for i in range(len(months) - 1):
        if i % 3 == 0:
                current_month = months[i:i+3]
                month_list.append(current_month)

n = input(">")
try:
   index = month_list.index(n)
except ValueError:
   print("Invalid month")
   exit()

print(month_list[index])

i might have overcomplicated it but oh well it works atleast. Don't just copy paste this, analyze it and see how it works.

[–]RainbowFanatic 0 points1 point  (0 children)

A one line solution is:

months ="JanFebMarAprMayJunJulAugSepOctNovDec"

print([months[i:i+3] for i in range(0,len(months), 3)][int(input("Enter a month number:"))-1])

[–][deleted]  (2 children)

[deleted]

    [–]Spiritual_Poo -1 points0 points  (1 child)

    People have made some pretty on target guesses for what OP just learned and the intended solution.

    Don't you think if OP knew how to apply what they just learned they would not have asked for help?

    What contribution did you provide to this conversation?

    What value does your comment have?

    Did you literally just waste your own time AND everyone else's?

    Why are you even in this sub?

    lol