作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个程序,它采用两个英制长度(英里、码、英尺和英寸)并输出它们的和与差。我的问题是,当差异为负时,输出不正确。
def to_inches(miles, yards, feet, inches):
return inches + (feet * 12) + (yards * 36) + (miles * 63360)
def from_inches(inches):
miles = inches // 63360
inches %= 63360
yards = inches // 36
inches %= 36
feet = inches // 12
inches %= 12
return (miles, yards, feet, inches)
units1 = [int(n) for n in input().split(' ')]
units2 = [int(n) for n in input().split(' ')]
m_sum = from_inches(to_inches(*units1) + to_inches(*units2))
m_diff = from_inches(to_inches(*units1) - to_inches(*units2))
print(' '.join(str(n) for n in m_sum))
print(' '.join(str(n) for n in m_diff))
输入:
2 850 1 7
1 930 1 4
输出:
4 21 0 11
0 1680 1 3
输入:
0 1 0 0
1 0 0 0
预期输出:
1 1 0 0
-0 1759 0 0
实际输出:
1 1 0 0
-1 1 0 0
最佳答案
这是因为当涉及到负数时,Python 对模运算符 %
的处理有点奇怪。查看此答案:https://stackoverflow.com/a/3883019/436282
关于python - 两个英制长度之差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24686370/
谁能推荐一个好的成员(member)结构? 例如,用户支付了 1 个月的成员(member)费,从 2012 年 2 月 1 日到 2012 年 3 月 1 日结束。 何时何地检查用户是否仍是成员(m
我想在我的 JTextPane 中实现查找机制(如文本编辑器或 word)。我希望它有下一个/上一个选项(向上/向下箭头)并突出显示它找到的所有单词。有没有简单的方法可以做到这一点? 最佳答案 我不是
Android 上是否有任何机制和/或编程实践来执行一次性安装/更新脚本?这似乎是一个非常基本的问题,但谷歌搜索没有帮助。 假设我的应用程序使用了一个数据库,并且需要一个常量值表(例如国家名称、城市名
是否可以将 SimpleMembership 与 ASP.NET WebForms 一起使用? John Galloway 的文章似乎表明 WebForms“在 ASP.NET 成员资格之上实现 OA
我是一名优秀的程序员,十分优秀!