繁体   English   中英

一行全部打印和输入

[英]Print and Input all in one line

如何将所有这些整合在一起? 您是否也看到一种更有效的方法?

import random  

# set the initial values
jersey = random.randint(1, 99)

print ("Who wears jersey no", jersey); input ("?");

输出为:

Who wears jersey no 11
?

您可以做类似的事情,

input("Who wears jersey no {}?".format(random.randint(1, 99)))

但是,不要一直在制造单线。 可读性很重要,如果这意味着要使用多行,请改为执行。

不确定将所有内容放在一行上是否可取,但是您可以这样做:

import random

a = raw_input('Who wears jersey no {}? '.format(random.randint(1,99)))

无论如何,一种不同于上述的替代方法:

input ("Who wears jersey no %s ?" % random.randint(1, 99));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM