• 代码6


    需要将相应数值转换为相应英文类别

    转换前的图:

    转换后的图

    错误代码:

    f = open('/home/xbwang/Desktop/intend.txt','r')
    trans = 'Error'
    for lines in f:if(line=='1'):
            trans = 'Weather'
        if(line=='2'):
            trans = 'Good'
        if(line=='3'):
            trans = 'Greeting'
        if(line=='4'):
            trans = 'HowTo_AddOfficialBot'
        if(line=='5'):
            trans = 'HowTo_AddPersonalBot'
        if(line=='6'):
            trans = 'HowTo_AutoReply'
        if(line=='7'):
            trans = 'HowTo_BotUsage'
        if(line=='8'):
            trans = 'HowTo_Buy'
        if(line=='9'):
            trans = 'HowTo_ChangeBotProfile'
        if(line=='10'):
            trans = 'HowTo_ChangeLogo'
        if(line=='11'):
            trans = 'HowTo_Complaint'
        if(line=='12'):
            trans = 'HowTo_CreateBot'
        if(line=='13'):
            trans = 'HowTo_DeleteBot'
        if(line=='14'):
            trans = 'HowTo_GetBackControl'
        if(line=='15'):
            trans = 'HowTo_Kickout'
        if(line=='16'):
            trans = 'HowTo_Stat'
        if(line=='17'):
            trans = 'HowTo_Subscribe'
        if(line=='18'):
            trans = 'IsAvailable'
        if(line=='19'):
            trans = 'IWillTry'
        if(line=='20'):
            trans = 'Ok'
        if(line=='21'):
            trans = 'Problem_BotNotWork'
        if(line=='22'):
            trans = 'Problem_FailedToAddBot'
        if(line=='23'):
            trans = 'Problem_FailedToChat'
        if(line=='24'):
            trans = 'Problem_FailedToKickout'
        if(line=='25'):
            trans = 'Problem_FailedToScanQRCode'
        if(line=='26'):
            trans = 'Question_Gongzhonghao'
        if(line=='27'):
            trans = 'Question_Hongbao'
        if(line=='28'):
            trans = 'Question_WhenCharge'
        if(line=='29'):
            trans = 'Problem_BotNotApproved'
        if(line=='30'):
            trans = 'ThankYou'
        f1 = open('/home/xbwang/Desktop/trans.txt','a')
        f1.write(trans+'
    ')

    文件中每行都写的Error

    正确代码:

    f = open('/home/xbwang/Desktop/intend.txt','r')
    trans = 'Error'
    for lines in f:
        line = lines[0]
        if(line=='1'):
            trans = 'Weather'
        if(line=='2'):
            trans = 'Good'
        if(line=='3'):
            trans = 'Greeting'
        if(line=='4'):
            trans = 'HowTo_AddOfficialBot'
        if(line=='5'):
            trans = 'HowTo_AddPersonalBot'
        if(line=='6'):
            trans = 'HowTo_AutoReply'
        if(line=='7'):
            trans = 'HowTo_BotUsage'
        if(line=='8'):
            trans = 'HowTo_Buy'
        if(line=='9'):
            trans = 'HowTo_ChangeBotProfile'
        if(line=='10'):
            trans = 'HowTo_ChangeLogo'
        if(line=='11'):
            trans = 'HowTo_Complaint'
        if(line=='12'):
            trans = 'HowTo_CreateBot'
        if(line=='13'):
            trans = 'HowTo_DeleteBot'
        if(line=='14'):
            trans = 'HowTo_GetBackControl'
        if(line=='15'):
            trans = 'HowTo_Kickout'
        if(line=='16'):
            trans = 'HowTo_Stat'
        if(line=='17'):
            trans = 'HowTo_Subscribe'
        if(line=='18'):
            trans = 'IsAvailable'
        if(line=='19'):
            trans = 'IWillTry'
        if(line=='20'):
            trans = 'Ok'
        if(line=='21'):
            trans = 'Problem_BotNotWork'
        if(line=='22'):
            trans = 'Problem_FailedToAddBot'
        if(line=='23'):
            trans = 'Problem_FailedToChat'
        if(line=='24'):
            trans = 'Problem_FailedToKickout'
        if(line=='25'):
            trans = 'Problem_FailedToScanQRCode'
        if(line=='26'):
            trans = 'Question_Gongzhonghao'
        if(line=='27'):
            trans = 'Question_Hongbao'
        if(line=='28'):
            trans = 'Question_WhenCharge'
        if(line=='29'):
            trans = 'Problem_BotNotApproved'
        if(line=='30'):
            trans = 'ThankYou'
        f1 = open('/home/xbwang/Desktop/trans.txt','a')
        f1.write(trans+'
    ')


    正确代码只比错误代码多了一行,因为从转换前文件读出的是字符串'数字'+' ',必须将 处理掉或者在判断中加上
  • 相关阅读:
    day12(jsp指令&内置对象&动作标签、JavaBean、EL表达式&函数库)
    day11(jsp入门&Cookie&HttpSession&一次性图片校验码)
    day10(java web之request&respone&访问路径&编码问题)
    day09:Servlet详解
    day08:软件系统的体系结构&Tomcat详解&Web应用&http协议
    泛型详解
    类加载器
    动态代理2
    动态代理3之代理工厂实现
    动态代理1
  • 原文地址:https://www.cnblogs.com/ymjyqsx/p/6253319.html
Copyright © 2020-2023  润新知