python书上的一道练习题,后面的
if __name__ == '__main__':
我不太明白,这个前后添加了双下划线的两个量在前文中也没有提到啊,它是什么意思呢?
完整的程序如下:
def division():
'''功能:分苹果'''
apple = int(input("请输入苹果的个数:"))
children = int(input("请输入来了几个小朋友:"))
result = apple // children
remain = apple - result * children
if remain > 0:
print(apple, "个苹果,平均分给", children, "个小朋友,每人分", result, "个,剩下", remain, "个。")
else:
print(apple,"个苹果,平均分给", children, "个小朋友,每人分", result, "个。")
if __name__ == '__main__':
try:
division()
except ZeroDivisionError:
print("\n出错了,苹果不能被0个小朋友分")
except ValueError as e:
print("输入错误:", e)
else:
print("分苹果顺利完成")