小编Sea*_*aus的帖子

函数round()不能像我期望的那样工作

我想在这里使用圆函数.有时它会从.5有时向上舍入.所以有什么问题?

源文件:

print("rounding up 0.5 is",round(.5))
print("rounding up 1.5 is",round(1.5))
print("rounding up 2.5 is",round(2.5))
print("rounding up 3.5 is",round(3.5))
Run Code Online (Sandbox Code Playgroud)

输出:

rounding up 0.5 is 0
rounding up 1.5 is 2
rounding up 2.5 is 2
rounding up 3.5 is 4
Run Code Online (Sandbox Code Playgroud)

python rounding python-3.x

3
推荐指数
1
解决办法
428
查看次数

将用户输入拆分为不同的变量

我想获取用户输入(如 IP 地址)并将各个部分拆分为单独的变量

例如

255.255.255.0

现在,我想按小数点拆分字符串并将每个部分保存到其自己的变量中。255 进入变量 1,第二个 255 进入变量 2,第三个 255 进入变量 3,0 进入变量 4 作为整数。

我怎样才能做到这一点?

python

0
推荐指数
1
解决办法
4169
查看次数

标签 统计

python ×2

python-3.x ×1

rounding ×1