Cho ngày sinh, nhiệm vụ là hiển thị cung hoàng đạo (Zodiac sign).
Ví dụ
Input : Ngày = 13, Tháng = November Output : Scorpio (Bò Cạp).
Thuật toán
Bước 1: Nhập ngày sinh. Bước 2: Kiểm tra tháng và ngày trong phạm vi hợp lệ của cung hoàng đạo chỉ định. Bước 3: Hiển thị cung hoàng đạo.
Mã ví dụ
def zodiac_sign(day, month): # Kiểm tra tháng và ngày trong phạm vi hợp lệ # của cung hoàng đạo chỉ định if month == 'december': astro_sign = 'Sagittarius' if (day < 22) else 'capricorn' elif month == 'january': astro_sign = 'Capricorn' if (day < 20) else 'aquarius' elif month == 'february': astro_sign = 'Aquarius' if (day < 19) else 'pisces' elif month == 'march': astro_sign = 'Pisces' if (day < 21) else 'aries' elif month == 'april': astro_sign = 'Aries' if (day < 20) else 'taurus' elif month == 'may': astro_sign = 'Taurus' if (day < 21) else 'gemini' elif month == 'june': astro_sign = 'Gemini' if (day < 21) else 'cancer' elif month == 'july': astro_sign = 'Cancer' if (day < 23) else 'leo' elif month == 'august': astro_sign = 'Leo' if (day < 23) else 'virgo' elif month == 'september': astro_sign = 'Virgo' if (day < 23) else 'libra' elif month == 'october': astro_sign = 'Libra' if (day < 23) else 'scorpio' elif month == 'november': astro_sign = 'scorpio' if (day < 22) else 'sagittarius' print(astro_sign) # Mã điều khiển if __name__ == '__main__': d = int(input("Nhập Ngày ::>")) m = input("Nhập Tháng ::>") zodiac_sign(d, m)Kết quả
Nhập Ngày ::>13 Nhập Tháng ::>november scorpio