【问题标题】:How can i fix this Type Error that appears? [closed]如何修复出现的此类型错误? [关闭]
【发布时间】:2019-02-18 12:50:00
【问题描述】:

我是 python 新手。对于学校的一个项目,我必须制作一种纸牌游戏。 这是我使用的代码:

playersDeckSize = deckSize / 2
i = 0
for i in range(int(playersDeckSize)):
   playerDeck[i] = cards[random.randint(0, len(cards - 1))]

   computerDeck[i] = cards[random.randint(0, len(cards - 1))]
   i = i + 1

【问题讨论】:

  • 你得到的完整错误是什么?
  • 欢迎来到 StackOverflow。请按照您创建此帐户时的建议阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布 MCVE 代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您描述的问题。
  • 甲板边是什么?

标签: python python-3.x list typeerror


【解决方案1】:

你的问题在于这个表达式:

len(cards - 1)

cards 似乎是一个列表;您不能从列表中减去 1。我怀疑你的意思是

len(cards) - 1

【讨论】:

    猜你喜欢
    • 2018-07-27
    • 2019-07-11
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    相关资源
    最近更新 更多