把一个三位数按个、十、百位分开的最快方法
1.介绍一个函数——divmod(x, y)
divmod(x, y)——返回x除以y的商和余数
例:divmod(5, 2) = (2, 1)
2.代码
(1)输入一个三位数s
s = int(input())
(2)取百位数字,和余数
a, b = divmod(s, 100)
(3)取十位数字和个位数字
b, c = divmod(b, 10)
(4)输出
print(a,b,c)
整理一下
s = int(input())
a, b = divmod(s, 100)
b, c = divmod(b, 10)
print(a,b,c)
浓缩一下,一行代码
print(divmod(int(input()), 100)[0], divmod(divmod(int(input()), 100)[1], 10)[0], divmod(divmod(int(input()), 100)[1], 10)[1])