首页 > 代码库 > 代码6
代码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+‘\n‘)
文件中每行都写的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+‘\n‘)
正确代码只比错误代码多了一行,因为从转换前文件读出的是字符串‘数字‘+‘\n‘,必须将\n处理掉或者在判断中加上\n
代码6
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。