我有这个项目,我无法弄清楚如何检查x或o是否赢了。另外我不知道如何使用count函数检查x或o是否被播放了太多次因为我添加列表的方式。您将在我的代码中理解:
if user_option == 0:
print("option 0")
print ("For each row, start with x. Enter a combination of x's "\
"and o's up to three characters. For a blank space," \
"enter a period '.'.")
msg = [ "top row", "middle row", "bottom row"]
col_size = 3
row_size = 3
ttt = list()
for n in range(col_size):
rows = input(msg[n]+ ":")
ttt.append(rows)
print(ttt)
valid_symbols = ['x','X','o','O','.']
done= False
for i in ttt:
if len(i) < 3:
print("invalid board - too few symbols")
break
elif len(i) > 3:
print("invalid board - too many symbols")
break
for x in i:
if x not in valid_symbols:
print("invalid board - invalid symbol "\
+ x )
done = True
break
else:
continue
for o in i:
if o not in valid_symbols:
print("invalid board - invalid symbol "\
+ o)
done = True
break
else:
break