首页 > 解决方案 > Python for 循环;将输入打印到 14 行中。随机数

问题描述

我有一个任务要编写一个程序来从用户那里读取一个整数,并将该数字用作种子值。接下来,生成 6 到 197 之间的 180 个随机数,用“}”分隔。以 14 行打印出来

import random


see= int(input("Please enter the seed value: "))
print(see)
random.seed(see)
for x in range (180):
        rand= random.randint(6,197)
        print(rand, end= "}")
        if x % 2 == 1:
            print()

问题是模运算符只给出 2 行。我正在使用模运算符,因为这是我教授建议的方法。

我无法弄清楚如何修改它以将其更改为打印为 14 行。

标签: pythonfor-loopprinting

解决方案


import random

see= int(input("Please enter the seed value: "))
print(see)
random.seed(see)
for x in range(180):
  rand = random.randint(6, 197)
  print(rand, end= "}")
  if ((x + 1) % 14 == 0):
      print()

推荐阅读