为什么在使用时间的时候会出现“无”字呢?

2024-10-05 12:22:55 发布

您现在位置:Python中文网/ 问答频道 /正文

import time
import random

print "Wanna play a game?"

raw_input(),\
time.sleep(1)
print ("Think of a number (1-5), I won't see, I promise. \n"),\
    time.sleep(5)

print "You picked? Now write it down."
raw_input(),\
time.sleep(3)

print ("Let me guess... \n"),\
    time.sleep(2)

print ((random.randint(1, 5))), \
    time.sleep(20000)

在终端中运行时,会发生以下情况:

Wanna play a game?

yes
Think of a number (1-5), I won't see, I promise. 
None
You picked? Now write it down.
Let me guess... 
None
1

为什么会弹出“无”


Tags: ofimportgamenumberinputplayrawtime
1条回答
网友
1楼 · 发布于 2024-10-05 12:22:55

代码中的,\向print语句添加新参数并打印它,在本例中,它是time.sleep()None)的返回值

去掉这些,固定压痕,它就工作了

import time
import random

print "Wanna play a game?"

raw_input()
time.sleep(1)
print ("Think of a number (1-5), I won't see, I promise. \n")
time.sleep(5)

print "You picked? Now write it down."
raw_input()
time.sleep(3)

print ("Let me guess... \n")
time.sleep(2)

print ((random.randint(1, 5)))
time.sleep(20000)

输出:

Wanna play a game?
y
Think of a number (1-5), I won't see, I promise. 
You picked? Now write it down.
1
Let me guess... 
3

相关问题 更多 >

    热门问题