E-book Travel Guides

Download E-book Travel Guides

ads
import datetime def calculate_age(year_of_birth): current_year = datetime.datetime.now().year age = current_year - year_of_birth return age def main(): try: year_of_birth = int(input("Nhập năm sinh của bạn: ")) if year_of_birth > datetime.datetime.now().year: print("Năm sinh không hợp lệ!") else: age = calculate_age(year_of_birth) print(f"Bạn hiện tại {age} tuổi.") except ValueError: print("Vui lòng nhập một số nguyên hợp lệ.") if __name__ == "__main__": main()

No comments:

Post a Comment

Socialize

Popular