python - 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 行。
解决方案
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()
推荐阅读
- python - 如何将 pyspark 数据帧写入红移数据库
- c++ - Visual Studio 19 GLFW 外部符号错误
- javascript - 在 Java 脚本中显示字符串中的字符数
- filter - 基于多个 Id 过滤对象的 OData 查询
- c++ - Qt creator 无法解析 stddef.h --> 不正确的代码完成和突出显示
- shopware - Shopware : 无法通过插件用户详细信息进行扩展
- java - @AliasFor 不适用于自定义注释中的属性
- r - 在R中的某些条件下对行求和
- swift - swiftui - 如何检测鼠标悬停在选择器中的元素上并显示弹出框
- php - 警告:current() 期望参数 1 是数组,给定 null