Skip to content

Question with repeated answer #4

@Denver-Dude

Description

@Denver-Dude

on week 1 python 5, the answer is repeated, please update with this answer

age = int(input())                     # int: Read a number as integer from standard input

dob = input().strip()                  # str: Read a string of format dd/mm/yy from standard input

day, month, year = map(int, dob.split('/'))  
# int, int, int: Get the correct parts from dob as int
# works with both 01/05/24 and 1/5/2024 style input

# Assuming 2-digit year means 2000+, adjust if needed
if year < 100:
    year += 2000

# Fifth birthday = same day/month + (year + 5)
fifth_birthday = f"{day}/{month}/{year + 5}"

# Last birthday = same day/month + age years
last_birthday = f"{day}/{month}/{year + age}"

# Tenth month = same day, month + 10 (may need to adjust year)
new_month = month + 10
extra_years = (new_month - 1) // 12
final_month = ((new_month - 1) % 12) + 1
tenth_month = f"{day}/{final_month}/{year + extra_years}"

# print tenth_month, fifth_birthday and last_birthday in same line separated by comma and a space
print(tenth_month, fifth_birthday, last_birthday, sep=", ")

weight = float(input())                # float: Read a number as float from stdin

kg = int(weight)                       # whole kilograms
grams = int(round((weight - kg) * 1000))

if grams == 0:
    weight_readable = f"{kg} kg"
else:
    weight_readable = f"{kg} kg {grams} grams"

# print weight_readable 
print(weight_readable)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions