![]() |
How i can judge my code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How i can judge my code (/thread-21495.html) Pages:
1
2
|
How i can judge my code - christing - Oct-02-2019 Below is the code i write for confirm my string single position. the purpose i write the code is i want single confirm my string(11111111111000000000000000000000) every position if the string position is one system will reply 1 or OK else if the string is 0 system will reply O OR NG try: mystring = "11111111111000000000000000000000" TEST1 = mystring.find('1')#POSITION JUDGE = "1" #JUDGE if TEST1 == JUDGE: TEST1 = "OK" else: TEST1 = "NG" #READ TEST2 = strTargetData[:TEST1+1] TEST2 = strTargetData[:TEST1+2] TEST2 = strTargetData[:TEST1+3] TEST2 = strTargetData[:TEST1+4] TEST2 = strTargetData[:TEST1+5] TEST2 = strTargetData[:TEST1+6] TEST2 = strTargetData[:TEST1+7] TEST2 = strTargetData[:TEST1+8] TEST2 = strTargetData[:TEST1+9] TEST2 = strTargetData[:TEST1+10] TEST2 = strTargetData[:TEST1+11] TEST2 = strTargetData[:TEST1+12] TEST2 = strTargetData[:TEST1+13] TEST2 = strTargetData[:TEST1+14] TEST2 = strTargetData[:TEST1+15] TEST2 = strTargetData[:TEST1+16] TEST2 = strTargetData[:TEST1+17] TEST2 = strTargetData[:TEST1+18] TEST2 = strTargetData[:TEST1+19] TEST2 = strTargetData[:TEST1+20] TEST2 = strTargetData[:TEST1+21] TEST2 = strTargetData[:TEST1+22] TEST2 = strTargetData[:TEST1+23] TEST2 = strTargetData[:TEST1+24] TEST2 = strTargetData[:TEST1+25] TEST2 = strTargetData[:TEST1+26] TEST2 = strTargetData[:TEST1+27] TEST2 = strTargetData[:TEST1+28] TEST2 = strTargetData[:TEST1+29] TEST2 = strTargetData[:TEST1+30] TEST2 = strTargetData[:TEST1+31] TEST2 = strTargetData[:TEST1+32] print (TEST2) my output is 11111111111000000000000000000000 RE: How i can judge my code - buran - Oct-02-2019 I don't know about other members, but for me it's not clear what you try to do. Also, what strTargetData is? What does "judge my code/string" means?
RE: How i can judge my code - christing - Oct-02-2019 (Oct-02-2019, 06:02 AM)buran Wrote: I don't know about other members, but for me it's not clear what you try to do. Also, what strTargetData is i write wrong info actaully i want to write mystring not strTargetData Good Day, the question I would like to ask is I can judge in (mystring = "1111111111100000000000") every single position. and want use 1 to judge. for example myjudge = "1" mystring = "1111111111100000000000" mystring[1] #this is the code i judge my string position 1 if mystring == "myjudge": print mystring = 1 else: print mystring = 0 my output will get 1 if the judgment is correct else will judge 0 actually I want to write the code on the simple way but I am no ideal how can I write my code on complex way I total write 32 times to judge (mystring=1111111111100000000000) result my output result is 1111111111100000000000 mystring[1] #this is the code i judge my string position 1 if mystring == "myjudge": print mystring = 1 else: print mystring = 0 I TOTAL WRITE THIS CODE 32 TIME now I am thinking how I can use for loop to write the code or another simple way to write the code RE: How i can judge my code - CoderMan - Oct-02-2019 Are you trying to know the position of all the 1s in your string or how many ones there are in your string? RE: How i can judge my code - christing - Oct-02-2019 (Oct-02-2019, 09:24 AM)CoderMan Wrote: Are you trying to know the position of all the 1s in your string or how many ones there are in your string? Good Day, I would like to know all mystring position event it is 1 or 0 RE: How i can judge my code - SheeppOSU - Oct-02-2019 I don't quite understand but I'm getting that you want to shorten the 32 lines of code. It could be shortened to this - for x in range(1, 33): TEST2 = mystring[:TEST1+x] RE: How i can judge my code - christing - Oct-02-2019 (Oct-02-2019, 12:39 PM)SheeppOSU Wrote: I don't quite understand but I'm getting that you want to shorten the 32 lines of code. It could be shortened to this -for x in range(1, 33): TEST2 = mystring[:TEST1+x] Good Day, If I want judge every mystring(1111111111000000000000000000000) position is under judgement 1 or not how can i add on the judgement. Thanks for your reply (Oct-02-2019, 09:24 AM)CoderMan Wrote: Are you trying to know the position of all the 1s in your string or how many ones there are in your string?My string have 32 position RE: How i can judge my code - ichabod801 - Oct-02-2019 Are you trying to get the positions where strTargetData equals mystring at that position? result = '' for target_char, my_char in zip(strTargetData, mystring): if target_char == my_char: result += '1' else: result += '0'? RE: How i can judge my code - christing - Oct-02-2019 (Oct-02-2019, 03:16 PM)ichabod801 Wrote: Are you trying to get the positions where strTargetData equals mystring at that position?I am trying use a simple way to judge my code as 1 actually is strTargetData this word is I write wrong.result = '' for target_char, my_char in zip(strTargetData, mystring): if target_char == my_char: result += '1' else: result += '0'? My string is 1111111111100000000000 I want my code judgement as 1 in my string 1111111111100000000000 in single position For example my string [1]#position1 is 1 My judgement =“1” my string == My judgement : Print (my string “1”) Else: Print (my string “0”) On this code output I will get 1 cause I judged 1 == 1 is correct Sorry I have not clear on your Code the result mean is .....why need use zip RE: How i can judge my code - jefsummers - Oct-02-2019 Some language barrier so we are guessing. Do you want: 1. A list of the digits, 1 or 0, from the source string 2. A list of OK or NG depending on whether the source string has 1 or 0 3. Two lists, with the positions of the 1s and 0s. Which, or if you can rephrase the question and do not use the word judge - that is causing confusion |