首页 > 其他分享 >Chapter 9

Chapter 9

时间:2022-12-13 15:22:05浏览次数:40  
标签:Chapter __ apple result print children 苹果

Division_apple

def division():
    print('\n==========分苹果了===========\n')
    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__':
division()

Division_apple_0

def division():
    print('\n==========分苹果了===========\n')
    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个小朋友分!')

Division_apple_1

def division():
    print('\n==========分苹果了===========\n')
    apple=int(input('请输入苹果的个数'))
    children=int(input('请输入来了多少个小朋友'))
    if apple<children:
        raise ValueError('苹果太少了,不够分...')
    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('\n出错了~_~-',e)

Division_apple_dug

def division():
    print('\n==========分苹果了===========\n')
    apple=int(input('请输入苹果的个数'))
    children=int(input('请输入来了多少个小朋友'))
    assert apple>children,'苹果不够分'
    result=apple//children
    remain=apple-result*children
    if remain>0:
        print(apple,'个苹果,平均分给',children,'个小朋友,每人分',result,'个,剩下',remain,'个。')
    else:
        print(apple,'个苹果,平均分给',children,'个小朋友,每人分',result,'个。')
try:
        division() 
except AssertionError as e:
        print('输入有误!',e)

 

标签:Chapter,__,apple,result,print,children,苹果
From: https://www.cnblogs.com/Kyaria-code-test/p/16978926.html

相关文章

  • Chapter 7
    GeeseclassGeese:'''大雁类'''def__init__(self,beak,wing,claw):print('我是大雁类!我有以下特征:')print(beak)print(wing)......
  • Chapter 8
    Bmibmi.pydeffun_bmi(person,height,weight):print(person+'的身高'+str(height)+'米\t体重:'+str(weight)+'千克')bmi=weight/(height*height)print(perso......
  • Chapter 6
    Function_tipsdeffunction_tips():importdatetimemot=["今天星期一:\n坚持下去不是因为我很坚强,而是因为我别无选择。","今天星期二:\n含泪播种的......
  • Chapter 4
    Datetimeimportdatetime#定义一个列表mot=["今天星期一:\n坚持下去不是因为我很坚强,而是因为我别无选择。","今天星期二:\n含泪播种的人一定能笑着收获。",......
  • Chapter6_与数据结构称为好朋友的七个要点
    热身问答程序中的变量是指什么?变量是数据的容器。变量中所存储的数据是可以改变的。变量的实质是按照变量所存储数据的大小被分配到的一块内存空间。把若干个数据......
  • Chapter5_与算法成为好朋友的七个要点
    热身问答Algorithm翻译成中文是什么?算法辗转相除法是用于计算什么的算法?是用于计算最大公约数的算法。最大公约数指的是两个整数的公共约数中最大的数。使用辗转......
  • Chapter7_成为会使用面向对象编程的程序员吧
    理解面向对象编程热身问答Object翻译成中文是什么?对象对象(Object)是表示事物的抽象名词。OOP是什么的缩略语?ObjectOrientProgramming面向对象也可以简称......
  • Chapter8_一用就会的数据库
    热身回答数据库术语中的“表”是什么意思?table,表示数据的集合表(Table)就是被整理成表格形式的数据一张表由若干个列和行构成。列也被称为字段(Field),行也被称为记录(Re......
  • Chapter9_通过七个简单的实验理解TCP_IP网络
    热身问答LAN是什么的缩略语?LAN是LocalAreaNetwork(局域网)的缩略语。通常把在一栋建筑物内或是一间办公室里的那种小规模网络称作LAN。与此相对,把互联网那样......
  • Chapter11_XML究竟是什么
    热身回答XML是什么的缩写?Extensiblemarkuplanguage可扩展标记语言所谓标记语言,就是可以用标签为数据赋予意义的语言。HTML和XML的区别是什么?HTML是网页,X......