[issue41436] BUG a simple "and" and "or"

2020-07-29 Thread Samran

Samran  added the comment:

Thanks a lot. I am beginner and will try stack overflow next time. Depending on 
the error type. Thank you again I learned a lot.

Sent from Mail for Windows 10

From: Karthikeyan Singaravelan
Sent: Wednesday, July 29, 2020 9:57 PM
To: iamsamra...@gmail.com
Subject: [issue41436] BUG a simple "and" and "or"

Karthikeyan Singaravelan  added the comment:

Below is the formatted program for easier reading. In the while clause you ask 
for the user to enter n to exit but you check (ch != n or ch != N) so on 
entering "n" the first condition is false but second clause is true. For "N" 
it's vice-versa. You want to continue the game as long as ch is not 'n' or "N'. 
Hence using not(ch == 'n' or ch == 'N') will help in exiting the program. This 
website is for bugs related to CPython itself. Please refer to stack overflow 
or other mailing lists in future.

Thanks.

from random import randint

num = randint(1, 10)

print(type(num))
print(num)

ch = None  # tried changing this tried converting types
guess = 0
print(type(guess))
print("Welcome to guessing game: ")

while (
ch != "n" or ch != "N"
):  # here is the bug this statement is not running. It works with “and”
while guess != num:
guess = int(input("Enter your guess?  "))
if guess == num:
print("You Guessed Congratz")
ch = input("Enter 'y' to play or 'n' to exit: ")
if ch == "y" or ch == "Y":
guess = 0
num = randint(1, 10)

print("Thankyou for playing.")

Fixed program : 

from random import randint

num = randint(1, 10)

print(type(num))
print(num)

ch = None  # tried changing this tried converting types
guess = 0
print(type(guess))
print("Welcome to guessing game: ")

while not (
ch == "n" or ch == "N"
):  # Play until the ch is not n or N 
while guess != num:
guess = int(input("Enter your guess?  "))
if guess == num:
print("You Guessed Congratz")
ch = input("Enter 'y' to play or 'n' to exit: ")
if ch == "y" or ch == "Y":
guess = 0
num = randint(1, 10)

print("Thankyou for playing.")

--
nosy: +jameshcorbett, xtreak
type: compile error -> behavior

___
Python tracker 
<https://bugs.python.org/issue41436>
___

--

___
Python tracker 
<https://bugs.python.org/issue41436>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41436] BUG a simple "and" and "or"

2020-07-29 Thread Samran


Samran  added the comment:

Thanks a lot. I am beginner and will try stack overflow next time. Depending on 
the error type. Thank you again I learned a lot.

Sent from Mail for Windows 10

From: James Corbett
Sent: Wednesday, July 29, 2020 9:57 PM
To: iamsamra...@gmail.com
Subject: [issue41436] BUG a simple "and" and "or"

James Corbett  added the comment:

I think this would have been a better fit for a StackOverflow issue: 
https://stackoverflow.com/questions/tagged/python. Also, it's not a compilation 
error and it doesn't have anything to do with CPython's testing framework. 

Anyway, I don't think this is a bug. For a string `ch`, it is always true that 
either `ch != 'n'` or `ch != 'N'`---no string is equal to both `'N'` and `'n'`. 
Therefore your `while` condition will always be true and the loop will always 
continue.

As you already noted, your loop will terminate properly if you used `and`. You 
could also rewrite it as `while ch not in ('n', 'N'):` which I think is clearer.

--
nosy: +jameshcorbett

___
Python tracker 
<https://bugs.python.org/issue41436>
___

--

___
Python tracker 
<https://bugs.python.org/issue41436>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41436] BUG a simple "and" and "or"

2020-07-29 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41436] BUG a simple "and" and "or"

2020-07-29 Thread James Corbett


James Corbett  added the comment:

I think this would have been a better fit for a StackOverflow issue: 
https://stackoverflow.com/questions/tagged/python. Also, it's not a compilation 
error and it doesn't have anything to do with CPython's testing framework. 

Anyway, I don't think this is a bug. For a string `ch`, it is always true that 
either `ch != 'n'` or `ch != 'N'`---no string is equal to both `'N'` and `'n'`. 
Therefore your `while` condition will always be true and the loop will always 
continue.

As you already noted, your loop will terminate properly if you used `and`. You 
could also rewrite it as `while ch not in ('n', 'N'):` which I think is clearer.

--
nosy: +jameshcorbett, xtreak
type: compile error -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41436] BUG a simple "and" and "or"

2020-07-29 Thread Karthikeyan Singaravelan

Karthikeyan Singaravelan  added the comment:

Below is the formatted program for easier reading. In the while clause you ask 
for the user to enter n to exit but you check (ch != n or ch != N) so on 
entering "n" the first condition is false but second clause is true. For "N" 
it's vice-versa. You want to continue the game as long as ch is not 'n' or "N'. 
Hence using not(ch == 'n' or ch == 'N') will help in exiting the program. This 
website is for bugs related to CPython itself. Please refer to stack overflow 
or other mailing lists in future.

Thanks.

from random import randint

num = randint(1, 10)

print(type(num))
print(num)

ch = None  # tried changing this tried converting types
guess = 0
print(type(guess))
print("Welcome to guessing game: ")


while (
ch != "n" or ch != "N"
):  # here is the bug this statement is not running. It works with “and”
while guess != num:
guess = int(input("Enter your guess?  "))
if guess == num:
print("You Guessed Congratz")
ch = input("Enter 'y' to play or 'n' to exit: ")
if ch == "y" or ch == "Y":
guess = 0
num = randint(1, 10)

print("Thankyou for playing.")


Fixed program : 

from random import randint

num = randint(1, 10)

print(type(num))
print(num)

ch = None  # tried changing this tried converting types
guess = 0
print(type(guess))
print("Welcome to guessing game: ")


while not (
ch == "n" or ch == "N"
):  # Play until the ch is not n or N 
while guess != num:
guess = int(input("Enter your guess?  "))
if guess == num:
print("You Guessed Congratz")
ch = input("Enter 'y' to play or 'n' to exit: ")
if ch == "y" or ch == "Y":
guess = 0
num = randint(1, 10)

print("Thankyou for playing.")

--
nosy: +jameshcorbett, xtreak
type: compile error -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41436] BUG a simple "and" and "or"

2020-07-29 Thread Samran

New submission from Samran :

#this is the code

from random import randint

num = randint(1,10)

print(type(num))

print(num)

ch = None   
#tried changing this tried converting types

guess = 0

print(type(guess))

print("Welcome to guessing game: ")

 

 

while ch != 'n' or ch != 'N':#here 
is the bug this statement is not running. It works with “and”

while( guess != num):

guess = int(input("Enter your guess?  "))

if guess == num:

print("You Guessed Congratz")

   

 

ch=input("Enter 'y' to play or 'n' to exit: ")

   

 

if ch=='y' or ch == 'Y':

guess= 0

num = randint(1,10)

 

print("Thankyou for playing.")

--
components: Tests
files: Command Prompt - python  test.py 29-Jul-20 9_16_22 PM (2).png
messages: 374576
nosy: Samran
priority: normal
severity: normal
status: open
title: BUG a simple "and" and "or"
type: compile error
versions: Python 3.8
Added file: https://bugs.python.org/file49347/Command Prompt - python  test.py 
29-Jul-20 9_16_22 PM (2).png

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com