@*Xiongqi ZHANG*
Sorry for being off topic. But how to get the code formatting in-mail ?


On Thu, Apr 9, 2015 at 11:06 AM, Luke Pebody <[email protected]> wrote:

> Quick code review:
>
> 1. Your use of .replace("\n", "") is to get rid of an ending newline. It
> is more pythonic to use .strip()
>
> 2. Suggest defining functions readInt() for int(s_input.readline()) and
> readWords() for s_input.readline().split(). Note that if you do not specify
> what you are splitting by, then you are splitting by chunks of whitespace.
>
> 3. Are you sure you are giving the correct answer when there is exactly
> one number in common on the corresponding rows?
>
> 4. When you set row = grid.append(...), you aren't using the variable row,
> so you can get rid of the "row=" part.
>
> 5. A bit picky here, but I don't agree with decreasing case_total by 1
> each case you do. The total number of cases stays the same. You could
> change the parameter name to cases_left, or change the condiyion to
> case_number <= case_total.
> On 9 Apr 2015 03:52, "Kenny Kang" <[email protected]> wrote:
>
>> Hi I'm new to programming so sorry if i seem very inexperienced.
>>
>> When I ran my magic trick program I wasn't able to get the correct answer
>> for every case. Can anyone help me find the problem in my program? I can't
>> seem to find what's wrong
>>
>>
>>
>> s_input = open("/home/pi/Desktop/Code Jam Practice/Code Jam 2014/Magic
>> Trick/A-small-practice.in", "r")
>> s_output = open("/home/pi/Desktop/Code Jam Practice/Code Jam 2014/Magic
>> Trick/A-small-practice.out", "w")
>>
>> case_total = int(s_input.readline())
>> case_number = 1
>>
>> #Test Case while case > 0
>> def test_case():
>>     global case_total
>>     global case_number
>>
>>     first_guess = int(s_input.readline().replace("\n", ""))
>>     grid_1 = []
>>     #Make grid 1
>>     for i in range(0,4):
>>         row = grid_1.append(s_input.readline().replace("\n", "").split("
>> "))
>>
>>     second_guess = int(s_input.readline().replace("\n", ""))
>>     grid_2 = []
>>     #Make grid 2
>>     for i in range(0,4):
>>         row = grid_2.append(s_input.readline().replace("\n", "").split("
>> "))
>>
>>     num_count = 0
>>     for i in grid_1[first_guess - 1]:
>>         if i in grid_2[second_guess - 1]:
>>             num_count += 1
>>     #Check Answer
>>     if num_count > 1:
>>         answer = "Bad magician!"
>>     elif num_count == 1:
>>         answer = i
>>     elif num_count == 0:
>>         answer = "Volunteer cheated!"
>>
>>     #Return Answer
>>     s_output.write("Case #%s: %s\n" % (case_number, answer))
>>     case_total -= 1
>>     case_number += 1
>>     print answer
>>
>> #run
>> while case_total > 0:
>>     test_case()
>>
>>
>> s_input.close()
>> s_output.close()
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google Code Jam" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/google-code/0caee8c6-18f8-4d63-9c53-b65fc2d35316%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/CAECKw-Od1DtYhicfaM6OEEZpqu5UNq4%3D_tcvANZ57VrJrXmu_g%40mail.gmail.com
> <https://groups.google.com/d/msgid/google-code/CAECKw-Od1DtYhicfaM6OEEZpqu5UNq4%3D_tcvANZ57VrJrXmu_g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CABGuxU_91Ak1Ryrw%2BVPSQTmqym_b6dGHr3UeP-7sOAuC-teaQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to