lundi 21 janvier 2019

Simplifying many if statements

I want to simplify the if statements instead of typing fifth_turn == each_turn_before

table()

fifth_turn = int(input('Player #1, select the spot you desire: '))


if fifth_turn == first_turn or fifth_turn == second_turn or fifth_turn == third_turn or fifth_turn == fourth_turn:
    print('Spot Taken')
elif fifth_turn == 1:
    spot1 = 'x'
elif fifth_turn == 2:
    spot2 = 'x'
elif fifth_turn == 3:
    spot3 = 'x'
elif fifth_turn == 4:
    spot4 = 'x'
elif fifth_turn == 5:
    spot5 = 'x'
elif fifth_turn == 6:
    spot6 = 'x'
elif fifth_turn == 7:
    spot7 = 'x'
elif fifth_turn == 8:
    spot8 = 'x'
elif fifth_turn == 9:
    spot9 = 'x'
else:
    print('ERROR')

Aucun commentaire:

Enregistrer un commentaire