Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please check code
#1
The program below implements computer
assistant, who asks the user day, month
and year of birth, and then display the age in years, months, and
days. It would be a very cool program, but someone hacked our system and made changes to the code! In the if statement
** characters appeared, and the variable no longer stores data!
Correct all errors and inaccuracies and run the program.
--- CODE
# Step 1
start import datetime
# Step 2
birth day = int(input("Day of birth: "))
birth month = int(input("Month of birth: "))
birth year = int(input("Year of birth: "))
day = int(datetime.date.today().day)
month = int(datetime.date.today().month)
year = int(datetime.date.today().year)
# Step 3
if * > **:
 age = year - birth_year
then:
 age = (year - birth_year) - 1
# Step 4
a = age
b = abs(month - birth_month)
c = abs(day - birth_day)
print("Your age: {a} years, {b} months, {c} days")
-----MY CODE PLEASE CHECK !!!
import datetime
# Step 2
birth_day = int(input("Day of birth: "))
birth_month = int(input("Month of birth: "))
birth_year = int(input("Year of birth: "))
day = int(datetime.date.today().day)
month = int(datetime.date.today().month)
year = int(datetime.date.today().year)
# Step 3

if year > birth_year:
 age = year - birth_year
else:
 age = (year - birth_year) - 1
# Step 4
a = age
b = abs(month - birth_month)
c = abs(day - birth_day)
print(f"Your age: {a} years, {b} months, {c} days")
Thanks!!!
Reply


Messages In This Thread
Please check code - by Evgeniy2019 - Apr-05-2019, 04:07 PM
RE: Please check code - by nilamo - Apr-05-2019, 04:24 PM
RE: Please check code - by Evgeniy2019 - Apr-05-2019, 04:26 PM
RE: Please check code - by nilamo - Apr-05-2019, 05:50 PM
RE: Please check code - by Evgeniy2019 - Apr-05-2019, 06:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Please check whether the code about the for loop question is correct. (SyntaxError) lilliancsk01 10 2,628 Nov-08-2022, 01:25 PM
Last Post: deanhystad
  Code Check? Am I right? r6lay 3 4,102 Mar-09-2017, 04:34 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020