import random
for x in range(5):
a = (random.randint(1,71))
b = "your numbers are"
c = str(a)
print(b + c)
如何获取输出“您的数字是x1,x2,x3,x4,x5”?
答案 0 :(得分:2)
我将使用字符串连接(下面的表达式,例如“ b + =“而不是“ b =”))来解决这样的问题:
import random
b = ""
for x in range(5):
a = (random.randint(1,71))
b += str(a)
# this part is only important if you care about having commas between numbers
if x < 4:
b += ", "
print("your numbers are " + b)