【问题标题】:I dont know whats wrong with my Python code im trying a simple randomiser and its not quite working我不知道我的 Python 代码有什么问题,我正在尝试一个简单的随机发生器,但它不太工作
【发布时间】:2013-03-03 08:25:35
【问题描述】:

这是我的代码

import time
import attacker
import random

"You sumble of the path and are confronted with "

attaker=random,randint(0,5)

if attacker==1:
    print" Gandalf"
if attaker==2:
    print" Harry Potter"
if attaker==3:
    print" a Smurf"
if attaker==4:
    print" a wierd dude with a sword "
if attaker==5:
    print" a Giant Spider"

语法错误是“回溯(最近一次调用最后一次): 文件“C:\Users\Nathan\Documents\V1”,第 3 行,在 进口攻击者 ImportError:没有名为攻击者的模块”

【问题讨论】:

    标签: python-2.7


    【解决方案1】:

    import attacker 在顶部假设有一个模块 Attacker.py 或 Attacker.pyc 。由于您使用攻击者来存储数字,我猜没有模块。因此出现错误。

    attaker=random,randint(0,5) 也应该是 attaker=random.randint(0,5)。点是调用模块变量或函数的方式。

    【讨论】:

      猜你喜欢
      • 2019-11-12
      • 2022-11-28
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 2020-10-23
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      相关资源
      最近更新 更多