keji_nb 2023-03-13 17:27 采纳率: 100%
浏览 24
已结题

python函数find报错

s='1803170101,干文娟,勘查1701,3.92,0.0,2.73,1.0,7.65;1803170102,古丽合妮姆·尤努斯,勘查1701,0.0,0.0,0.4,0.5,0.9;1803170103,洪荐英,勘查1701,3.46,0.0,1.8,0.5,5.76;1803170104,李智彬,勘查1701,2.73,0.3,1.53,0.5,5.06;1803170105,唐思倩,勘查1701,4.09,0.3,4.8,0.5,9.69;1803170106,辛盛涵,勘查1701,4.09,0.3,4.67,0.5,9.56;1803170107,徐凤婷,勘查1701,3.55,0.6,3.2,0.5,7.85;1803170108,虞悦,勘查1701,3.72,0.6,9.0,1.0,14.32;1803170109,艾合买提江·阿布地热木,勘查1701,1.36,0.0,0.6,0.5,2.46;1803170110,陈思为,勘查1701,1.36,0.3,1.67,1.0,4.33;1803170111,陈有鑫,勘查1701,3.75,0.6,4.87,1.0,10.22;1803170112,龚春华,勘查1701,1.36,0.0,0.73,1.0,3.09;1803170114,顾旭珠,勘查1701,1.36,0,1.2,0.5,3.06;1803170115,郭子豪,勘查1701,1.19,0.0,0.93,0.5,2.62;1803170116,何德祺,勘查1701,1.36,0.0,1.27,0.5,3.13;1803170117,何国亮,勘查1701,1.19,0.0,1.6,0.5,3.29;1803170118,何家兴,勘查1701,1.19,0.3,2.27,1.0,4.76;1803170119,何先斌,勘查1701,3.8,0.0,3.4,0.5,7.7;1803170120,胡舒寒,勘查1701,3.92,0.3,3.07,1.0,8.29;1803170121,黄英建,勘查1701,1.36,0.0,2.13,1.0,4.49;1803170122,黎志强,勘查1701,1.36,0.0,0.4,1.0,2.76;1803170123,梁强,勘查1701,3.5,0.0,3.73,1.0,8.23;1803170124,梁宇轩,勘查1701,1.36,0.0,0.73,0.5,2.59;1803170125,林惠明,勘查1701,1.36,0.3,2.6,1.0,5.26;1803170126,马振波,勘查1701,3.46,0.6,7.8,1.0,12.86;1803170127,时英喆,勘查1701,1.02,0.0,1.47,1.0,3.49;1803170129,张栋,勘查1701,0.0,0.0,0.4,1.0,1.4;1803170130,张禄,勘查1701,1.36,0.0,1.2,1.0,3.56;'
print(s.count('勘查'))
print(s.find(begin(input()),end(;)))

这个为什么老是报错,题目如下:
2) 文本中每个人的成绩是以10位学号开始,最后以西文状态下的分号结束。请编程输出某个学号(代码运行时通过键盘输入)的一整条平时成绩记录,如‘1803170108,虞悦,勘查1701,3.72,0.6,9.0,1.0,14.32’。

  • 写回答

2条回答 默认 最新

  • 小小小小人水豚 2023-03-13 18:10
    关注
    s = '1803170101,干文娟,勘查1701,3.92,0.0,2.73,1.0,7.65;1803170102,古丽合妮姆·尤努斯,勘查1701,0.0,0.0,0.4,0.5,0.9;1803170103,洪荐英,勘查1701,3.46,0.0,1.8,0.5,5.76;1803170104,李智彬,勘查1701,2.73,0.3,1.53,0.5,5.06;1803170105,唐思倩,勘查1701,4.09,0.3,4.8,0.5,9.69;1803170106,辛盛涵,勘查1701,4.09,0.3,4.67,0.5,9.56;1803170107,徐凤婷,勘查1701,3.55,0.6,3.2,0.5,7.85;1803170108,虞悦,勘查1701,3.72,0.6,9.0,1.0,14.32;1803170109,艾合买提江·阿布地热木,勘查1701,1.36,0.0,0.6,0.5,2.46;1803170110,陈思为,勘查1701,1.36,0.3,1.67,1.0,4.33;1803170111,陈有鑫,勘查1701,3.75,0.6,4.87,1.0,10.22;1803170112,龚春华,勘查1701,1.36,0.0,0.73,1.0,3.09;1803170114,顾旭珠,勘查1701,1.36,0,1.2,0.5,3.06;1803170115,郭子豪,勘查1701,1.19,0.0,0.93,0.5,2.62;1803170116,何德祺,勘查1701,1.36,0.0,1.27,0.5,3.13;1803170117,何国亮,勘查1701,1.19,0.0,1.6,0.5,3.29;1803170118,何家兴,勘查1701,1.19,0.3,2.27,1.0,4.76;1803170119,何先斌,勘查1701,3.8,0.0,3.4,0.5,7.7;1803170120,胡舒寒,勘查1701,3.92,0.3,3.07,1.0,8.29;1803170121,黄英建,勘查1701,1.36,0.0,2.13,1.0,4.49;1803170122,黎志强,勘查1701,1.36,0.0,0.4,1.0,2.76;1803170123,梁强,勘查1701,3.5,0.0,3.73,1.0,8.23;1803170124,梁宇轩,勘查1701,1.36,0.0,0.73,0.5,2.59;1803170125,林惠明,勘查1701,1.36,0.3,2.6,1.0,5.26;1803170126,马振波,勘查1701,3.46,0.6,7.8,1.0,12.86;1803170127,时英喆,勘查1701,1.02,0.0,1.47,1.0,3.49;1803170129,张栋,勘查1701,0.0,0.0,0.4,1.0,1.4;1803170130,张禄,勘查1701,1.36,0.0,1.2,1.0,3.56;'
    num = input('请输入学号:')
    # 找到开始位置
    start = s.find(num)
    # 找到结束位置
    end = s.find(';', start)
    if start > 0 and end > 0:
        print(s[start: end])
    

    有帮助的话,请点采纳该答案~

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月21日
  • 已采纳回答 3月13日
  • 创建了问题 3月13日

悬赏问题

  • ¥15 我想通过python处理sybase IQ库的一些数据,但是不知道sybase IQ库怎么连接,之前连接都是用linux上的 dbisql
  • ¥15 安装llama-cpp-python==0.1.83失败
  • ¥20 管道轴向耦合水击问题
  • ¥60 补全networkx TODO部分。
  • ¥15 有内推吗,云计算linux运维方向
  • ¥30 sort cuteSV.vcf by bcftools用IGV可视化出现报错
  • ¥100 SOS!对STK中导出的天体图像进行质心提取有没有人做过啊
  • ¥15 python 欧式距离
  • ¥15 遗传算法解决有工序顺序约束的大规模FJSP问题
  • ¥15 企业消防水炮塔设计方案