Re: Problem with printing statement when condition is false

2021-03-05 Thread Terry Reedy

On 3/4/2021 4:28 PM, Terry Reedy wrote:

Quentin privately sent me 12 lines (which should have been posted here 
instead), which can be reduced to the following 4 that exhibit his bug.


if a == b:
     print('correct')
     if a != b:
     print('incorrect')

The bug is a != b will never be true when a == b and will not be tested 
when a != b.  The fix is to use else.


if a == b:
     print('correct')
else:
     print('incorrect')

This should not be reduced to a conditional expression since different 
code follows the print statements in the actual example.


Quentin wrote me privately that this, applied to his code, solved his 
problem.



--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with printing statement when condition is false

2021-03-04 Thread Terry Reedy

On 3/4/2021 3:15 PM, Terry Reedy wrote:

On 3/4/2021 12:10 PM, Quentin Bock wrote:


I won't paste the code into
this because it's 164 lines so I will attach a file copy,


The alternative to posting too much is to reduce your code to the 
minimum needed to exhibit the behavior you want to change.  Doing so may 
reveal to you the solution.  It will certainly make it easier for anyone 
else to help you and will make any answer more useful to other readers.


Quentin privately sent me 12 lines (which should have been posted here 
instead), which can be reduced to the following 4 that exhibit his bug.


if a == b:
print('correct')
if a != b:
print('incorrect')

The bug is a != b will never be true when a == b and will not be tested 
when a != b.  The fix is to use else.


if a == b:
print('correct')
else:
print('incorrect')

This should not be reduced to a conditional expression since different 
code follows the print statements in the actual example.


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with printing statement when condition is false

2021-03-04 Thread Terry Reedy

On 3/4/2021 12:10 PM, Quentin Bock wrote:


I won't paste the code into
this because it's 164 lines so I will attach a file copy,


The alternative to posting too much is to reduce your code to the 
minimum needed to exhibit the behavior you want to change.  Doing so may 
reveal to you the solution.  It will certainly make it easier for anyone 
else to help you and will make any answer more useful to other readers.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Problem with printing statement when condition is false

2021-03-04 Thread Quentin Bock
Okay so, this is my biggest project, I'm not advanced in Python in any
way so don't expect it to be perfect. I made a trivia game and for the most
part, it works but I can't get it to print "Incorrect" and then what the
answer was for all but one of my questions and I don't know why. I use
PyCharm as my IDE for his just as a heads up. I won't paste the code into
this because it's 164 lines so I will attach a file copy, please don't send
back the edited file only write them out and where I need to fix them,
thank you!
Stay Safe Everyone! :)


Virus-free.
www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
-- 
https://mail.python.org/mailman/listinfo/python-list