作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
你如何编写一个程序来从用户整数输入开始向上和向下计数,只使用一个 while 循环而不使用 for 或 if 语句?
我已经成功地倒数了,但似乎无法弄清楚如何倒数。它也需要看起来像一个横向三角形,数字前有空格(等于打印的数字)。
到目前为止,这是我的代码;
n = int(input("Enter an integer: "))
i = " "
lines = 0
while lines <= n-1:
print(i * lines + str(lines))
lines += 1
最佳答案
您可以通过充分利用负数和绝对值来解决这个问题:abs()
这将允许您在初始数字通过零时“切换方向”:
n = int(input("Enter an integer: "))
s = " "
i = n * -1
while i <= n:
num = n - abs(i)
print(s * num + str(num))
i += 1
这将产生:
Enter an integer: 3
0
1
2
3
2
1
0
关于python - 一个 while 循环来向上和向下计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63787164/
我知道 Jobs 可以通过 flink 或 flink.bat 提交给 JobManager。我想知道Flink有没有提供Java API给JobManager提交作业? 最佳答案 是的。根据您要连接
我已经将 GCM 的演示代码应用于 appache 服务器的服务器端和 android 设备的客户端,并且运行良好;但我需要在我的应用程序中激活此服务,如下所示:我在 SqlServer 上有一个数据
我需要将自定义 header 添加到 WebView 中加载的页面,但它不起作用, header 未设置: @Override public WebResourceResponse shouldInt
我是一名优秀的程序员,十分优秀!