I am working in Jupyter Notebook with Python 3.6. I do not understand why all the values are being appended to winning_numbers instead of losing_numbers where they should.
My code:
import numpy as np
winning_numbers = []
losing_numbers = []
limit = 11
for x in range(1, limit):
if x%2 == 0:
if x-1 or x/2 in losing_numbers:
winning_numbers.append(x)
elif x-1 and x/2 in winning_numbers:
losing_numbers.append(x)
if x%2 == 1:
if x-1 == 0:
winning_numbers.append(x)
elif x-1 or (x-1)/2 in losing_numbers:
winning_numbers.append(x)
elif x-1 and (x-1)/2 in winning_numbers:
losing_numbers.append(x)
print("Winning Numbers: ", winning_numbers)
print("Losing Numbers: ", losing_numbers)
My output is:
Winning Numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Losing Numbers: []
The output should be:
Winning Numbers: [1, 3, 4, 5, 7, 9]
Losing Numbers: [2, 6, 8, 10]
Aucun commentaire:
Enregistrer un commentaire