Computer >> Máy Tính >  >> Lập trình >> Python

Chương trình Python để hiển thị dấu hiệu Chiêm tinh hoặc dấu hiệu Hoàng đạo cho một dữ liệu nhất định về ngày sinh.

Với ngày sinh, nhiệm vụ của chúng ta là hiển thị dấu hiệu chiêm tinh hoặc dấu hiệu Hoàng đạo.

Ví dụ

Input : Day = 13, Month = November
Output : Scorpio.

Thuật toán

Step 1 : input date of birth.
Step 2 : checks month and date within the valid range of a specified zodiac.
Step 3 : display zodiac sign.

Mã mẫu

def zodiac_sign(day, month):
   # checks month and date within the valid range
   # of a specified zodiac
   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)

# Driver code
if __name__ == '__main__':
d = int(input("Enter Day ::>"))
m = input("Enter the Month ::>")
zodiac_sign(d, m)

Đầu ra

Enter Day ::>13
Enter the Month ::>november
scorpio