python - python not excecuting if statement
问题描述
The start() is for reference use later for my code.
import os
import random
import time
import replit
playing = ['player1', 'player2']
space = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
def draw():
print('\n ',space[0],'|',space[1],'|',space[2],' ')
print(' ---+---+---')
print(' ',space[3],'|',space[4],'|',space[5],' ')
print(' ---+---+---')
print(' ',space[6],'|',space[7],'|',space[8],'\n')
def ask(prompt):
ask = input(prompt)
return ask
def start():
pick = input('Who go first X / O\n>> ') #this is for reference later
if pick == 'X' or pick == 'x':
print('selected X')
time.sleep(1)
replit.clear()
draw()
play(ask('Choose number\n>> '))
def play(ans):
if ans == 1:
space[0] = 'X'
elif ans == 2:
space[1] = 'O'
draw()
start()
print(space[0])
All of the functions are working properly they are executing fine except for the play() inside it the space[0] = 'X' is not happening, why is that?
解决方案
因为ask
返回一个字符串,而不是一个整数。
推荐阅读
- javascript - 使用本机反应创建页面构建器
- javascript - 单击信息窗口内的按钮时更改谷歌地图标记图标
- java - 在 Unique Constrains JPA/Hibernate 期间添加自定义错误消息的更好方法
- java - 如何在 JavaFX 可编辑 TreeTableView 中提供货币编辑(LongProperty)?
- flutter - 断言失败:第 556 行 pos 15:'scrollOffsetCorrection != 0.0':不正确
- javascript - TypeError:无法读取未定义的属性“FieldValue”
- angular - Angular 9 的 ngx-translate 在 IE 中不起作用
- google-apps-script - 社区连接器教程导致“未知数据源”
- class - 为什么不能在飞镖类中的方法体之外打印任何语句
- python-3.x - 如何使用 selenium python 从 Outlook 下载嵌入的 content-id 图像