How can I shorten my code for this? There are 6 variable sets of numbers, someone picks a number between 1-63, if their number is in a set, you add the first number of the list to the magic number variable. If it is not, you don't add anything, and move to the next set. I have used multiple while loops, but want a more effective way to do this.
number_set1 = [2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31, 34, 35, 38, 39, 42, 43, 46, 47, 50, 51, 54, 55, 58, 59, 62, 63]
number_set2 = [8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31, 40, 41, 42, 43, 44, 45, 46, 47, 56, 57, 58, 59, 60, 61, 62, 63]
number_set3 = [4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31, 36, 37, 38, 39, 44, 45, 46, 47, 52, 53, 54, 55, 60, 61, 62, 63]
number_set4 = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
number_set5 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63]
number_set6 = [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
answer = ''
magic_number = 0
index = 0
print('I can read your mind... think of a number between 1 to 63 (inclusive)')
print('Don\'t tell me... just be sure to keep it in your mind... I\'ll work it out')
print('by having you answer a few, simple questions.... :)')
answer = input('Would you like to play? [Yes|No] :')
if answer != "Yes" and answer != "No":
print("\nPlease enter either 'Yes' or 'No'.")
while answer == 'Yes' and index == 0:
question = input('Is your number in deck 1? [Yes|No] :')
if question == 'Yes':
magic_number = magic_number + number_set1[0]
index = index + 1
if question == 'No':
index = index + 1
while answer == 'Yes' and index == 1:
question = input('Is your number in deck 2? [Yes|No] :')
if question == 'Yes':
magic_number = magic_number + number_set2[0]
index = index + 1
if question == 'No':
index = index + 1
while answer == 'Yes' and index == 1 or index == 2:
question = input('Is your number in deck 3? [Yes|No] :')
if question == 'Yes':
magic_number = magic_number + number_set3[0]
index = index + 1
if question == 'No':
index = index + 1
while answer == 'Yes' and index == 2 or index == 3:
question = input('Is your number in deck 4? [Yes|No] :')
if question == 'Yes':
magic_number = magic_number + number_set4[0]
index = index + 1
if question == 'No':
index = index + 1
while answer == 'Yes' and index == 3 or index == 4:
question = input('Is your number in deck 5? [Yes|No] :')
if question == 'Yes':
magic_number = magic_number + number_set5[0]
index = index + 1
if question == 'No':
index = index + 1
while answer == 'Yes' and index == 4 or index == 5:
question = input('Is your number in deck 6? [Yes|No]: ')
if question == 'Yes':
magic_number = magic_number + number_set6[0]
index = index + 1
if question == 'No':
index = index + 1
# Display the secret number to the screen and amaze your friends! ; )
print('The number you are thinking about is.....', magic_number)