【发布时间】:2017-07-10 20:57:47
【问题描述】:
我正在尝试对用户输入出生月份和日期后的星座进行编码。
print("To figure out your horoscope, enter the following questions")
month = int(input("what month were you born(january,december,august: "))
days = int(input("what day were you born(2,4,12: "))
if month == 'december':
astro_sign = 'Sagittarius are nice people' if (day < 22) else 'Capricon are adventurous'
print(astro_sign)
但是,每次我执行代码时,它都会给我一个错误:
print(astro_sign)
NameError: name 'astro_sign' is not defined
目前,我只放了一个月,即 12 天,天在 22 岁以下,稍后当这段代码工作时,我将添加更多月份。谁能帮帮我吗?
【问题讨论】:
-
if month == 12: -
只有在月份为 12 时才定义 astro_sign。
标签: python python-3.x