Str对象不可用于使用Python连接四个游戏的TypeError调用

问题描述 投票:0回答:1

我正在通过制作四连环游戏来练习Python,但我一直陷在这个错误中,我不确定应该采取哪些下一步措施来修复它。在第108行的文件“ main.py”中player1()TypeError:“ str”对象不可调用

import pandas as pd

data = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 
0, 0], [0, 0, 0, 0 ,0, 0]] 

df = pd.DataFrame(data, columns = ['A', 'B', 'C', 'D', 'E', 'F'])

print(df)

a = df['A']
b = df['B']
c = df['C']
d = df['D']
e = df['E']
f = df['F']

player1 = 'H'
player2 = 'X'

for i in range(len(df)):
  a_cell = a[i]
  b_cell = b[i]
  c_cell = c[i]
  d_cell = d[i]
  e_cell = e[i]
  f_cell = f[i]

  # Prevents board piece from changing after changed once
  if a[i] == 'X' or a[i] == 'H':
    a[i] != player1.inputs or player2.inputs
  if b[i] == 'X' or b[i] == 'H':
    b[i] != player1.inputs or player2.inputs
  if c[i] == 'X' or c[i] == 'H':
    c[i] != player1.inputs or player2.inputs
  if d[i] == 'X' or d[i] == 'H':
    d[i] != player1.inputs or player2.inputs
  if e[i] == 'X' or e[i] == 'H':
    e[i] != player1.inputs or player2.inputs
  if f[i] == 'X' or f[i] == 'H':
    f[i] != player1.inputs or player2.inputs  

# Places board pieces from input
def player1():

  if player1 == "a" and a[i] != "X" and a[i] != "H":
    a[i] = "H"
    print(df)

  elif player1 == "b" and b[i] != 'X' and b[i] != 'H':
    b[i] = "H"
    print(df)

  elif player1 == "c" and c[i] != 'X' and b[i] != 'H':
    c[i] = "H"
    print(df)

  elif player1 == "d" and d[i] != 'X' and b[i] != 'H':
    d[i] = "H"
    print(df)

  elif player1 == "e" and e[i] != 'X' and b[i] != 'H':
    e[i] = "H"
    print(df)

  elif player1 == "f" and f[i] != 'X' and b[i] != 'H':
    f[i] = "H"
    print(df)

  else:
    player1 = input("Player1, select a correct board piece: ")
    player1()

def player2():    

  if player2 == "a" and a[i] != "X" and a[i] != "H":
    a[i] = "X"
    print(df)

  elif player2 == "b" and b[i] != 'X' and b[i] != 'H':
    b[i] = 'X'
    print(df)

  elif player2 == "c" and c[i] != 'X' and c[i] != 'H':
    c[i] = "X"
    print(df)

  elif player2 == "d" and d[i] != 'X' and d[i] != 'H':
    d[i] = "X"
    print(df)

  elif player2 == "e" and e[i] != 'X' and e[i] != 'H' :
    e[i] = "X"
    print(df)

  elif player2 == "f" and f[i] != 'X' and f[i] != 'H':
    f[i] = "X"
    print(df)

  else:
    player2 = input("Player2, select a correct board piece: ")
    player2()

player1 = "H"
player2 = "X"
player1 = input("Player1, select board piece: ")
while True:

  if player1 == 'a' or player1 == 'b' or player1 == 'c' or player1 == 'd' or player1 == 'e' or 
  player1 == 'f':
    player1()
    player2 = input("Player2, select board piece: ")


  elif player2 == 'a' or player2 == 'b' or player2 == 'c' or player2 == 'd' or player2 == 'e' or 
  player2 == 'f':
    player2()
    player1 = input("Player1, select board piece: ")

[它还说局部变量'player1'在赋值之前引用的第114行的封闭范围内定义,并且在'109行上有'player2'的一个]]

我正在通过制作四连环游戏来练习Python,但我一直陷在这个错误中,我不确定应该采取哪些下一步措施来修复它。在player1()中的文件“ main.py”,第108行TypeError:'str'...

python pandas dataframe typeerror function-call
1个回答
0
投票

您为函数和字符串使用相同的名称。首先,定义称为player1player2的函数。然后,在第105行中,当您从player1捕获文本时,将字符串分配给变量input。因此,当您随后尝试在第110行调用player1()时,会收到错误消息,因为无法调用字符串。

© www.soinside.com 2019 - 2024. All rights reserved.