Python Forum
Output not following rules set in code.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Output not following rules set in code.
#4
(Apr-24-2019, 01:52 AM)Escribblings Wrote: As for what you say about the 25, the thing is that send to be working. It's the lines if x == 50: that seem to be being ignored.

It is not working. Test it yourself:

if (25 and 20 and 15) != 25:
     print("It's broken")
else:
     print("It works")
The and of two non-zero numbers is the number on the right. So as long as the last number is 25, and the first two numbers are non-zero (guaranteed since you're adding two numbers from 1 to 24), that will be true.

I gave you the correct format: if 25 not in (corner2[0] + corner2[1], corner2[0] + corner2[2], corner2[1] + corner2[2]):. In the above example, this would simplify to if 25 not in (15, 20, 25): which would be False, since 25 is in the tuple. The easiest thing to do is just combine them with and's: if a + b != 25 and a + c != 25 and a + d != 25:.

Your all version does not work because it evaluates the all first. All of those sums are non-zero integers, which evaluate to True. So they are all True, and the all version simplifies to if True != 25:, which is always true.

In terms of converting to functions, start with checking things. Make a function that returns True if a side is valid and False if it isn't. Do the same for a corner, and so on.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Output not following rules set in code. - by ichabod801 - Apr-24-2019, 12:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 462 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  I cannot able to see output of this code ted 1 808 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  why I dont get any output from this code William369 2 1,191 Jun-23-2022, 09:18 PM
Last Post: William369
  How can I organize my code according to output that I want ilknurg 1 1,225 Mar-11-2022, 09:24 AM
Last Post: perfringo
  Why this code not getting desired output ? MDRI 2 2,620 Sep-18-2020, 02:11 AM
Last Post: MDRI
  Read excel file to determine the rules abc12345 4 2,769 May-13-2020, 12:59 PM
Last Post: abc12345
  I couldn't understand the output of the below code ravich129 1 1,982 Dec-12-2019, 06:24 AM
Last Post: sandeep_ganga
  Output of Python code hemal07yc 5 4,105 Sep-13-2019, 11:33 AM
Last Post: perfringo
  What will the following code output? dukoolsharma 5 3,361 Dec-15-2018, 06:05 AM
Last Post: HarshaliPatel
  No output for the code to read emails avani9659 6 4,343 Aug-14-2018, 08:30 AM
Last Post: avani9659

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020