def division(): apple = int(input('请输入苹果个数:')) children = int(input('请输入几个小朋友:')) result = apple // children remain = apple % children if __name__ == '__main__': try: division() except (ZeroDivisionError, ValueError) as e: print('输入错误', e)
############################################
def division(): apple = int(input('请输入苹果个数:')) children = int(input('请输入几个小朋友:')) result = apple // children remain = apple % children if __name__ == '__main__': try: division() except (ZeroDivisionError, ValueError) as e: print('输入错误', e) else: print('分苹果顺利完成')
####################################################
def division(): apple = int(input('请输入苹果个数:')) children = int(input('请输入几个小朋友:')) result = apple // children remain = apple % children if __name__ == '__main__': try: division() except (ZeroDivisionError, ValueError) as e: print('输入错误', e) else: print('分苹果顺利完成') finally: print('进行了一次分苹果操作') ############################################################
def division(): apple = int(input('请输入苹果个数:')) children = int(input('请输入几个小朋友:')) if apple<children: raise ValueError('苹果太少了,不够分') result = apple // children remain = apple % children if __name__ == '__main__': try: division() except (ZeroDivisionError, ValueError) as e: print('输入错误', e) else: print('分苹果顺利完成') finally: print('进行了一次分苹果操作')