Question

In: Computer Science

Modify this python program to print "Happy Birthday!" if today is the person's birthday. Remember that...

Modify this python program to print "Happy Birthday!" if today is the person's birthday. Remember that a person has a birthday every year. It is not likely that a newborn will wonder into a bar the day s/he is born. Your program should print "Happy Birthday!" if today's month and day are the same as the person's birthday. For example, if person is born November 3, 1984 and today is November 3, 2019, then a happy birthday message should print.

The code:

import datetime

from dateutil.relativedelta import relativedelta

today = datetime.date.today()
today



"""from .. import * considered bad form."""

# from datetime import *

"""This is better style."""

from datetime import date

today

type(today)

today.month

today.day

#@title Enter birthday
bday_input = "1995-06-15" #@param {type:"date"}
bday_input = input('Enter your birthday: ')
bday_input

bday_comps = bday_input.split('-')
year = bday_comps[0]
month = bday_comps[1]
day = bday_comps[2]
print(month, day, year)

type(year)

year, month, day = bday_input.split('-')
print(month, day, year)

type(year)

bday = datetime.date(int(year), int(month), int(day))
bday

diff = relativedelta(today, bday)
diff

diff.years

if diff.years >= 21:
  print('Welcome!')
  print('Stamp hand.')
else:
  print('Piss off kid.')
print('Next!')

Solutions

Expert Solution

From your given program, I have removed insignificant libraries and modified the program to give your required output. The program will be required to input the birthday date in the exact way asked (as per your given code)

Here is the code:

import datetime
from datetime import date   #imported required library

today = datetime.datetime.today()   #today will consist the data of the current date
today_month=today.month
today_day=today.day

bday_input = "1995-06-15" #@param {type:"date"} #taking birthday input
bday_input = input('Enter your birthday: ')

bday_comps = bday_input.split('-')   #separating the input into three parts-day,month,year
year = int(bday_comps[0]) #typecasting into "int"
month = int(bday_comps[1])
day = int(bday_comps[2])

if month==today_month and day==today_day: #comparison of the input birthday date with today's date
print("Happy Birthday !") #if the birthday date and today's date matches, it prints "HappyBirthday"
else:
print("Hey, It's not your birthday today")


Related Solutions

PYTHON Modify the program in section Ask the user for a first name and a last...
PYTHON Modify the program in section Ask the user for a first name and a last name of several people.  Use a loop to ask for user input of each person’s first and last names  Each time through the loop, use a dictionary to store the first and last names of that person  Add that dictionary to a list to create a master list of the names  Example dictionary: aDict = { "fname":"Douglas", "name":"Lee" } ...
2) create a python program that uses a for loop and range to print out the...
2) create a python program that uses a for loop and range to print out the values 10 8 6 4 2 3) Create a python program that yses a for loop to print out ["bob","al","bert"]
[PYTHON] Modify the examaverages.py program included with this assignment so it will also compute the overall...
[PYTHON] Modify the examaverages.py program included with this assignment so it will also compute the overall average test grade. E.g if there are 3 test each student must take and the user enters the following set of test scores for the two students…: 30, 40, 50 for the first student 50, 60, 70 for the second student …then program will print the average for each student (i.e. 40 for the first student and 60 for the second student – the...
Write a program in Python that will print first 100 numbers of the following series: 0,...
Write a program in Python that will print first 100 numbers of the following series: 0, 1, 1, 2, 3, 5, 8……..
Python Write a program that will analyse the string input and print “accept” or “reject” based...
Python Write a program that will analyse the string input and print “accept” or “reject” based on the pattern given Accept if it fulfils the following conditions -String length 9 -3 small alphabet (3 lowercase letter) -3 digits -3 big alphabet (3 uppercase letters) -1st alphabet should be a capital -Last alphabet should be a number -Two consecutive alphabets can't be small Reject if any of the conditions is absent So i want it to accept or reject my input,...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Write a program in Python to print all possible combinations of phone numbers. The length of...
Write a program in Python to print all possible combinations of phone numbers. The length of the number will be given. Also 3 digits will be given, which can not be used. No two consecutive digits can be same. A number containing 4 would always have 4 in the beginning.
In python....Modify the recursive Fibonacci program given in the textbook so that it prints tracing information....
In python....Modify the recursive Fibonacci program given in the textbook so that it prints tracing information. Specifically, have the function print a message when it is called and when it returns. For example, the output should contain lines like these: Computing fib(4) OR Leaving fib(4) returning 3
In Python b) Modify your program that reads 3 grades from the user (and computes the...
In Python b) Modify your program that reads 3 grades from the user (and computes the average and letter grade) so that it uses a while loop to read the 3 grades. In the loop body, you will just read one grade and update other variables appropriately. The loop header will ensure 3 iterations. c) Modify your program in part b so that it asks the user how many grades there are and uses a while loop to read that...
PYTHON Let n denote an integer entered by the user. Write a program to print n...
PYTHON Let n denote an integer entered by the user. Write a program to print n multiples of 5 in the descending order, with the last number being 5. Print the average of those n multiples
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT