Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8637273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:26:19+00:00 2026-06-12T10:26:19+00:00

Hi I am a beginner in python, and I was trying to create a

  • 0

Hi I am a beginner in python, and I was trying to create a program where a date is entered and displayed in a program

I tried to implement loops for when the user entered a number outside the limits. For determining the month the while loop worked fine:

month = int(input("Which numeric month of the year were you born in?\n"))
while((month <=0) or (month >12)):
    print("The Month must be within the range 12>= Month >0. Please enter the value again.")
    print("\n")
    month = int(input("Which numeric month of the year were you born in?\n"))

However, for the second part (below), determining the day, when the user inputs a value for the month of February, which is limited to 28 days, the looped message it shows is for a different condition (the third if statement in the day set) instead.

If you enter: 2 for month, and 30 for day. The message it loops is:

…30< month =<0

instead of showing:

28< month =<0

Can someone please help me figure out how to use the while statement properly?

My code is the following:

day = int(input("Which numeric day of the month were you born in?\n"))
while(month == 1,3,5,7,8,10,12):
    if(day <=0) or (day >31):
        print("For your selected month, the value for day must be within the range 31>= Day >0. Please enter the value again.")
        print("\n")
        day= int(input("Which numeric day of the month were you born in?\n"))
while(month ==2):
    if(day <=0) or (day >28):
        print("For your selected month, the value for day must be within the range 28>= Day >0. Please enter the value again.")
        print("\n")
        day= int(input("Which numeric day of the month were you born in?\n"))
while(month ==4,6,9,11):
    if(day <=0) or (day >30):
        print("For your selected month, the value for day must be within the range 30>=Day>0. Please enter the value again.")
        print("\n")
        day= int(input("Which numeric day of the month were you born in?\n"))

Note that I am limited to only beginner level python codes when using this. The most I can do beyond this is use for loops instead of while loops, but nothing more advanced than that.

The program should display the individuals birth date at the end of the program.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:26:20+00:00Added an answer on June 12, 2026 at 10:26 am

    You have too many while loops. Out of some of them you can never escape.

    After you know which month you have, you should decide how many days you have in this month:

    So you have

    month = int(input("Which numeric month of the year were you born in?\n"))
    while((month <=0) or (month >12)):
        print("The Month must be within the range 12>= Month >0. Please enter the value again."):
        print("\n")
        month = int(input("Which numeric month of the year were you born in?\n"))
    if month in (4, 6, 9, 11): # short
        maxdays = 30
    elif month != 2: # not February -> long
        maxdays = 31
    else:
        # Here we could ask for the year, determine if the year is divisible by 4, by 100 and by 400 and with this information determie if we have a leap year, but...
        # we are tolerant for now and accept the 29 as well.
        maxdays = 29
    

    Now you can work with what you have without repeating yourself too often:

    day = int(input("Which numeric day of the month were you born in?\n"))
    if(day <= 0) or (day > maxdays):
        print("For your selected month, the value for day must be within the range {0} >= Day > 0. Please enter the value again.".format(maxdays))
        print("\n")
        day = int(input("Which numeric day of the month were you born in?\n"))
    

    If you haven’t learned format() yet, you can do

        print("For your selected month, the value for day must be within the range " + str(maxdays) + " >= Day > 0. Please enter the value again.")
    

    or even

        print("For your selected month, the value for day is wrong. Please enter the value again.")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner in python and I'm trying to use a octal number in
I'm a very beginner in python and django. However I'm trying to create a
I am a Python beginner trying to count the number of certain sizes in
I'm a beginner developer in Gtk and also in Python. I'm trying to create
I am quite a beginner to Python and trying to get my head around
I am a beginner of Python. I am trying now figuring out why the
I am a beginner with Python and trying few programs. I have something like
I am a beginner with python and I am trying to print the results
I'm trying to get simple code working, unfortunately I'm a python beginner. My script
I am totally a beginner and now trying to implement a simple search engine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.