键盘读入 name, birth_year, birth_month, birth_day。这三个变量分别代表你的姓名, 出生年与出生月份。程序将打印:'你好, name, 你 x 岁了,你是 constellation。',其中 constellation 是指这个出生年月对应的星座。此外,这是个多轮对话,要求能够多次读入(注 意,不是多次运行程序,而是运行一次程序就可以做到这点)。当 birth_year 等于-1 时程 序退出,退出时打印:'再见!'。
1条回答 默认 最新
- CSDN专家-天际的海浪 2021-10-24 22:17关注403 Forbidden https://www.jb51.net/article/62955.htm
你题目的解答代码如下:
import datetime #计算星座 def Zodiac(month, day): n = ('摩羯座','水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座','狮子座','处女座','天秤座','天蝎座','射手座') d = ((1,20),(2,19),(3,21),(4,21),(5,21),(6,22),(7,23),(8,23),(9,23),(10,23),(11,23),(12,23)) return n[len(list(filter(lambda y:y<=(month,day), d)))%12] while True: name = input("请输入姓名:") birth_year, birth_month, birth_day = input("请输入出生年 月 日(以空格分隔):").split(" ") birth_year = int(birth_year) birth_month = int(birth_month) birth_day = int(birth_day) if birth_year == -1: break today = datetime.date.today() x = today.year - birth_year constellation = Zodiac(birth_month,birth_day) print(f"你好, {name}, 你 {x} 岁了,你是 {constellation}。") print("再见!")
如有帮助,望采纳!谢谢!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
- ¥20 神经网络Sequential name=sequential, built=False
- ¥16 Qphython 用xlrd读取excel报错
- ¥15 单片机学习顺序问题!!
- ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
- ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
- ¥15 相敏解调 matlab
- ¥15 求lingo代码和思路
- ¥15 公交车和无人机协同运输
- ¥15 stm32代码移植没反应