下面是我在打印随机数的python程序。我要做的是仅使用一个打印命令进行打印。
import random
x = list(range(1,100))
y = list(range(1,100))
x = random.sample(x,6)
y = random.sample(y,1)
print("I think the lottery's winning numbers are ",x)
print('\nand the powerball should be ', y)
答案 0 :(得分:0)
Python可以满足您的要求!像abc这样简单:
print("I think the lottery's winning numbers are {}\nand the powerball should be {}".format(x, y))
请注意,如何使用这种简单的方法将变量放入字符串中,即可轻松地将其放入所需的{}中。
对于将来执行更复杂的任务,这可能而且肯定会派上用场。例如,您可以使用此输入法来检查域中是否存在某个子域数组:
http.request('GET','https://pagetorequest.com/{}.php'.format(subdomains_to_check[index]))
答案 1 :(得分:0)
尝试一下
print("I think the lottery's winning numbers are {} \n and the powerball should be {}".format(x, y))
答案 2 :(得分:0)
您可以这样打印:
print(f"I think the lottery's winning numbers are {x} and the powerball should be {y}")
在“ str”之前添加f允许使用{variable}直接在字符串中添加变量