鱼C论坛

 找回密码
 立即注册
查看: 1653|回复: 6

[已解决]零基础学习Python

[复制链接]
发表于 2017-8-23 18:21:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import random
secret = random.ranint(1,10)
temp = input("请输入我心里想的是什么数字吧:")
guess = int(temp)
while guess != secret:
    if guess == secret:
        print("你猜中了")
        print("擦擦擦")
    else:
        if guess > secret:
            print("大了大了")
        else:
                print("小了小了")
print("游戏结束,不玩啦~~")
              
结果:        
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
============ RESTART: C:/Users/Administrator/Desktop/实验/12345.py ============
Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/实验/12345.py", line 2, in <module>
    secret = random.ranint(1,10)
AttributeError: module 'random' has no attribute 'ranint'
>>>
是我模块引不进的问题吗
最佳答案
2017-8-23 19:01:36

>>> dir(random) #random模块是系统自带模块,不会没有的,出现此问题是没有import random
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    dir(random)
NameError: name 'random' is not defined
>>> dir(randint)
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    dir(randint)  #需要dir(random.randint)
NameError: name 'randint' is not defined
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-8-23 18:26:37 | 显示全部楼层
还有个问题,这图片形式怎么整出来的,我不会。。。
88888.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-23 18:35:04 | 显示全部楼层
在IDLE中用dir(random)查询你的函数写对没,我记得好像是randint()。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-8-23 18:48:49 | 显示全部楼层
>>> dir(random)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    dir(random)
NameError: name 'random' is not defined
>>> dir(randint)
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    dir(randint)
NameError: name 'randint' is not defined
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-8-23 18:49:31 | 显示全部楼层
是我没有random这模块吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-23 19:01:36 | 显示全部楼层    本楼为最佳答案   

>>> dir(random) #random模块是系统自带模块,不会没有的,出现此问题是没有import random
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    dir(random)
NameError: name 'random' is not defined
>>> dir(randint)
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    dir(randint)  #需要dir(random.randint)
NameError: name 'randint' is not defined
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-23 19:05:40 | 显示全部楼层
2017-08-23_190341.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-3 20:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表