Please see comments below

   1. s_input = open("/home/pi/Desktop/Code Jam Practice/Code Jam
   2014/Magic Trick/A-small-practice.in", "r")
   2. s_output = open("/home/pi/Desktop/Code Jam Practice/Code Jam
   2014/Magic Trick/A-small-practice.out", "w")
   3.
   4. case_total = int(s_input.readline())
   5. case_number = 1
   6.
   7. #Test Case while case > 0
   8. def test_case():
   9. global case_total
   10. global case_number
   11.
   12. first_guess = int(s_input.readline().replace("\n", ""))
   13. grid_1 = []
   14. #Make grid 1
   15. for i in range(0,4):
   16. row = grid_1.append(s_input.readline().replace("\n", "").split(" "))
   17.
   18. second_guess = int(s_input.readline().replace("\n", ""))
   19. grid_2 = []
   20. #Make grid 2
   21. for i in range(0,4):
   22. row = grid_2.append(s_input.readline().replace("\n", "").split(" "))
   23.
   24. num_count = 0
   25. for i in grid_1[first_guess - 1]:
   26. if i in grid_2[second_guess - 1]:
   27. answer = i # you should set answer to i here
   28. num_count += 1
   29. #Check Answer
   30. if num_count > 1:
   31. answer = "Bad magician!"
   32. # you shouldn't set answer to i at this point as i may not be the
   correct answer anymore
   33. #elif num_count == 1:
   34. # answer = i
   35. elif num_count == 0:
   36. answer = "Volunteer cheated!"
   37.
   38. #Return Answer
   39. s_output.write("Case #%s: %s\n" % (case_number, answer))
   40. case_total -= 1
   41. case_number += 1
   42. print answer
   43.
   44. #run
   45. while case_total > 0:
   46. test_case()
   47.
   48.
   49. s_input.close()
   50. s_output.close()


Parker

On Thu, Apr 9, 2015 at 10:53 AM 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/CAGDEU-J34MN1X3Huqz01UZMTZ6L4Xg%2Bmc1bC3xSkDBL%3DB17GtQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to