星座问题:顶级逻辑~

  • 时间:
  • 浏览:
  • 来源:互联网
f = open("PY301-SunSign.csv", 'r', encoding="utf-8")
ls = []
for line in f:
    ls.append(line.strip(' \n').split(','))
f.close()
while True:
    x = input("请输入星座序号(例如,5):")
    num = x.strip(' \n').split()
    for i in num:
        if 0 < int(i) < len(ls):  # 文件中有标题行,所以ls中多一行
            for row in ls:
                if row[0] == i:
                    m1 = row[2][0] if len(row[2]) == 3 else row[2][0:2]
                    d1 = row[2][1:3] if len(row[2]) == 3 else row[2][2:4]
                    m2 = row[3][0] if len(row[2]) == 3 else row[3][0:2]
                    d2 = row[3][1:3] if len(row[2]) == 3 else row[3][2:4]
                    print("{}({})的生日是{}月{}日至{}月{}日之间".format(row[1], row[4], m1, d1, m2, d2))
        else:
            print("输入星座序号有误!")

本文链接http://www.dzjqx.cn/news/show-617498.html