|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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'
>>>
是我模块引不进的问题吗
>>> 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
|
|