Help me in solving PYTH106 problem

My issue

Write a program which does the following

You are given a list consisting of 12 integers - the number of days in each month in a year
You need to iterate through the loop and exit the loop if you find any integer which is not 30 or 31
Output this anomaly to the console

My code

days = [30, 31, 30, 30, 31, 30, 20, 30, 31, 30, 31, 30]

for index, day in enumerate(days):
    if day != 30 and day != 31:
        anomaly_month = index + 1
        print("Anomaly found in month:", anomaly_month)
        break

Learning course: Python with Data structures
Problem Link: CodeChef: Practical coding for everyone

Hi @p_20it247

days_in_months = [31, 28, 31, 29, 31, 30, 31, 31, 30, 31, 30, 31]
for i in days_in_months:
if i!=30 and i!=31:
print(i)

Thank you :smiley:

1 Like
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

for I in days:
    if I != 30 or I != 31:
        anomaly_month = days.index(I)
        print("Anomaly found in month:", anomaly_month)
        break
    print(I)

I hope this will help you it, I tried to kept all the variables you declared in your code so that it will be easy for you to understand

#lovecoding

2 Likes