Question

code in python: Build a program that askes for the user to input their birthday. Capture...

code in python:

Build a program that askes for the user to input their birthday.

Capture the birthdate and do the math to calculate how many days between todays date and their

birthday.

If their birthday has already passed, show the message “It’s been XX days since your birthday”

If their birthday is coming up, show the message “It’s XX days until your birthday”

If today is their birthday, show the message “Happy Birthday!”

Note: Date math produces a datatype called timedelta. In order to make this work, you have to

capture the number of days in a string and then parse out what you need. Make sure you account

for negative numbers if your birthday has passed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

from datetime import date
  
userInput = raw_input('Enter your birthday in YYYY-MM-DD format \n')
print userInput
year, month, day = map(int, userInput.split('-'))
today = date.today()
date1 = date(today.year, month, day)

DaysRemain = (date1 -today).days

if DaysRemain > 0:
print "It's " + str(DaysRemain) + " days until your birthday"
elif DaysRemain < 0:
print "It's been " + str(DaysRemain) + " days since your birthday"
elif DaysRemain == 0:
print "Happy Birthday!"

Add a comment
Know the answer?
Add Answer to:
code in python: Build a program that askes for the user to input their birthday. Capture...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write in python code Project 11-1: Birthday Calculator Create a program that accepts a name and...

    Write in python code Project 11-1: Birthday Calculator Create a program that accepts a name and a birth date and displays the person's birthday the current day, the person's age, and the number of days until the person's next birthday Console Birthday Calculator Enter name: Joel Enter birthday (MM/DD/YY): 2/4/68 Birthday: Sunday, February 04, 1968 Today: Joel is 48 years old. Joel's birthday is in 73 days Tuesday, November 22, 2016 Continue? (y/n): y Enter name: Django Enter birthday (MM/DD/YY):...

  • Write a C++ program that determines the user's age after the user enters both the current...

    Write a C++ program that determines the user's age after the user enters both the current date and hisher birthdate as 3 integers: yyyy mm dd Define a class which is named DateType and will be used to declare 2 objects: "birthday" and "today". The class will have a function "output" which will display the date in conventional form (like it is above next to Date Assigned: Month dd, yyyy EXAMPLE: If the user entered the #’s: 2018 2 6...

  • Write a C++ program that determines the user's age after the   user enters both the current...

    Write a C++ program that determines the user's age after the   user enters both the current date and hisher birthdate as 3   integers:                yyyy mm dd                                                                                             Define a class which is named DateType and will be used to     declare 2 objects: "birthday" and "today". The class will have a function "output" which will display the date in conventional form (like it is above next to Date Assigned: Month dd, yyyy and it will have a second function named     “input”...

  • PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do...

    PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do one of five things at a time: 1. Add students to database. • There should be no duplicate students. If student already exists, do not add the data again; print a message informing student already exists in database. • Enter name, age, and address. 2. Search for students in the database by name. • User enters student name to search • Show student name,...

  • in python Write a program that reads the date of birth from the user as 3...

    in python Write a program that reads the date of birth from the user as 3 integer values (day, month, year) and then computes and prints their exact age in days. You need to take into account the leap You may not use any built-in functions related to date and time! Example: Someone born on 01/01/2000 is 365 days * 18 years + 5 days (since the years 2000, 2004, 2008, 2012, and 2016 are all leap years) + 352...

  • IN PYTHON Exercise 4 Build a single chatbot that takes input from the user and behaves...

    IN PYTHON Exercise 4 Build a single chatbot that takes input from the user and behaves in the following way: 1. If the input is a "I feel [..] statement, the chatbot responds by asking "Why do you feel that way"? 2. If the input is a "Can you [predicate] " question, the chatbot responds by saying "Sure, I can [predicatel all day." 3. If the input is a "Did you [predicatel" question, the chatbot responds by saying "No, I...

  • C++ : Please include complete source code in answer This program will have names and addresses...

    C++ : Please include complete source code in answer This program will have names and addresses saved in a linked list. In addition, a birthday and anniversary date will be saved with each record. When the program is run, it will search for a birthday or an anniversary using the current date to compare with the saved date. It will then generate the appropriate card message. Because this will be an interactive system, your program should begin by displaying a...

  • Using PYTHON create a program to allow the user to enter a phrase or read a...

    Using PYTHON create a program to allow the user to enter a phrase or read a file. Make your program menu-driven to allow the user to select a option to count the total words in the phrase or file. In addition, provide a menu-selection to count the number of words start with a vowel and a selection to count the number of words that start with a consonant. Include exception handlers for file not found, divide by zero, and index...

  • Your friend is writing a Python program to randomly provide the user with an inspiring quote....

    Your friend is writing a Python program to randomly provide the user with an inspiring quote. Unfortunately, your friend is a terrible programmer, and you promised to help them with their program. Basically, there is a list of inspirational sayings in the code, and the program enters a loop and gives the user a random quote. The program is then supposed to ask the user if they want another quote. If they answer anything other than ‘y’ the program ends....

  • PYTHON Build a regular expressions based on informal specifications to match specified patterns. Use a compiled...

    PYTHON Build a regular expressions based on informal specifications to match specified patterns. Use a compiled regular expression in a Python program where appropriate. Use Python's text processing str methods to generate a string format converter. create a date format converter. Your program will convert a date in the format “mm/dd/yyyy” to the format “month day, year”. Specify the required input format: mm/dd/yyyy Use a regular expression to validate the user input date format. If the format is incorrect raise...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT