一个Python程序,该程序从用户获得数字并总结其字符,但两个特定号码除外
例如,给定的数字为4211256:我想总结所有数字而不添加11;给定编号添加的结果将是:19
我写了程序代码的第一部分,但我无法继续
n=int(input("Enter number: "))
sum=0
for digit in str(n):
sum=sum+int(digit)
while 11:
pass
print("Sum of digits",sum)
for example, the given number is 4211256: I want to sum all the digits without adding 11; the result of the given number addition will be: 19
I wrote the first part of the program code but I couldn't continue it
n=int(input("Enter number: "))
sum=0
for digit in str(n):
sum=sum+int(digit)
while 11:
pass
print("Sum of digits",sum)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下操作:
通过用“”替换“ 11”(无需将n转换为整数然后返回到字符串),您可以摆脱“ 11”,然后总结剩余的数字。
Try this:
You get rid of '11' by replacing '11' with '' (there's no need to convert n to an integer and then back to a string), and then you sum the remaining digits.
尝试此选项并计算部分总和:
Try this option and calculate the sums in parts: