AC代码展示 fi = open ( "SunSign.csv" , "r" , encoding = "utf-8" ) d = { '水瓶座' : 1 , '双鱼座' : 2 , '白羊座' : 3 , '金牛座' : 4 , \ '双子座' : 5 , '巨蟹座' : 6 , '狮子座' : 7 , '处女座' : 8 , \ '天秤座' : 9 , '天蝎座' : 10 , '射手座' : 11 , '摩羯座' : 12 , } ls = [ ] for row in fi : ls . append ( row . strip ( '\n' ) . split ( ',' ) ) chaxun = input ( ) if d . get ( chaxun , False ) == False : print ( "输入星座名称有误" ) else : ind = d . get ( chaxun , 0 ) print ( "{}座的生日位于{}-{}之间。" . format ( ls [ ind ] [ 0 ] [ 0 : 2 ] , ls [ ind ] [ 1 ] , ls [ ind ] [ 2 ] ) ) 来源: https://blog.csdn.net/onionycs/article/details/100767681