I'm not quite sure why you are using while loops. I believe you want to ask if move1 in range(1, 10)
(by the way no need to write range(0, 10, 1) because step is by default 1, and also your tic tac toe board goes from 1 to 9 not from 0 hence range(1, 10)). This would be like saying "if move1 is not a number between 1 and 9, then ask for an input". I think what you mean is also if move1 == ''
. There is also a small problem with this, which is that inputs are strings... so they can't really be compared with a number from the range. i.e. '3' != 3.
To easily change that, you can just do int(input(".. whatever you ask for .."))
which converts the string into integers.
Just a side note but when you write move1 = ''
, I know you're using empty string because you don't have anything, but you can also use move1 = None
. Then you could also say if not move1:
instead ("None" is False, so it's like saying if not False i.e if True).
Up until now, you've got:
def play_sequence():
move1 = None
if not move1:
move1 = int(input("Player 1, choose a number:"))
Also, you could make it much easier by just saying
def play_sequence():
move1 = int(input("Player 1, choose a number:"))
because there isn't much point in making move1 when you are going to change it anyway. Unless I didn't quite understand why you were using the while loop... I guess you wanted to check whether the input is a number between 1-9?
Anyway, the problem you found with the weird "1 1 1" stems from this:
while move1 == input(move1):
print("You chose 1")
Here, you use input(), and whenever you have input(), you actually ask for an input. That's why you're putting 1 again and again. If you write 2 or some other number for example, then the while loop stops. I'm actually not quite sure what you are doing here, but I think what you were trying to say is:
print("You chose", move1)
This would print the number which was chosen in the first part of your function.
Hence:
def play_sequence():
move1 = None
if not move1:
move1 = int(input("Player 1, choose a number:"))
print("You chose", move1)
I hope I'm helping and I didn't confuse you... :) Have fun learning python though!