首页 > 其他分享 >13 刘欣晨 第九章实例+实战

13 刘欣晨 第九章实例+实战

时间:2022-12-23 17:00:51浏览次数:23  
标签:__ 13 apple 第九章 刘欣晨 苹果 print children result

实验 一  项目名称:      模拟幼儿园分苹果

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()

实验 二  项目名称:    模拟幼儿园分苹果(除数不能为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 ZerpoDivisionError:
    print("\n出错了~_~--苹果不能被个小朋友分!")

  except ValueError as e:

    print("输入错误:",e)

实验 三  项目名称:      模拟幼儿园分苹果(每个人至少分到一个苹果)

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 ZerpoDivisionError:
    print("\n出错了~_~--苹果不能被个小朋友分!")
  except ValueError as e:
    print("输入错误:",e)

实验 四  项目名称:      模拟幼儿园分苹果(应用断言调试)

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,"个。")

if __name__ == '__main__':
  division()

 

标签:__,13,apple,第九章,刘欣晨,苹果,print,children,result
From: https://www.cnblogs.com/L13538196467/p/17001021.html

相关文章

  • SpringBoot2.x系列教程13--SpringBoot开发利刃之热部署原理及最优实践
    SpringBoot系列教程13--SpringBoot开发利刃之热部署原理及最优实践作者:一一哥一.SpringBoot的热部署1.概述SpringBoot为开发者提供了一个名为spring-boot-devtools的额外工......
  • m基于A律13折线法与μ律15折线的信号压缩MATLAB仿真
    1.算法概述        在通信中,由于信号量噪比的不恒定而影响通信质量。为了对不同的信号强度保持信号量噪比恒定,在理论上要求压缩特性为对数特性。为了使信号量噪比......
  • Educational Codeforces Round 139 D. Lucky Chains
    LuckyChains题面翻译给定两个数·a,b,(a,b给到了1e7)执行如下语句:while(gcd(a,b)==1)a++,b++,cnt++;求出cnt的值。样例#1样例输入#145151337891......
  • 全志A133 Android10 Display框架实践
    一、Sunxi平台图形开发术语全志A133采用的DISP2的框架,即DE2.0版本。对应kernel的配置:CONFIG_DISP2_SUNXI=y   1、硬件术语1)layer:一个图层处理单元,可以处理一张......
  • 第九章 克隆虚拟机
    第九章克隆虚拟机9.1克隆从现有虚拟机(关机状态)克隆出新虚拟机,右键选择管理=>克隆点击下一步选择虚拟机中的当前状态选择创建完整克隆设置虚拟机名称......
  • 20221222 13. RBAC
    使用RBAC鉴权|KubernetesServiceAccounts用户账户与服务账户Kubernetes区分用户账户和服务账户的概念主要基于以下原因:User(用户账户)是针对人而言的。Servi......
  • [CF1325E] Ehab's REAL Number Theory Problem
    Ehab'sREALNumberTheoryProblem题目描述Youaregivenanarray$a$oflength$n$thathasaspecialcondition:everyelementinthisarrayhasatmost7......
  • 20221322 实验八-Web部署 实验报告
    Web部署(openEuler中基于LAMP部署WordPress)实验过程一、配置openEuler华为云openEuler安装后,没有配置yum源,我们通过重新配置。cd/etc/yum.repos.dviopenEuler_x86......
  • 超标量处理器设计——第九章_执行
    参考《超标量处理器》姚永斌著目录超标量处理器设计——第九章_执行9.1概述9.2FU类型9.2.1ALU9.2.2AGU9.2.3BRU条件码分支正确性检查9.3旁路网络9.3.1简单设计......
  • Cpp Primer:Sec 13:拷贝控制
    目录Sec13拷贝控制13.1拷贝、赋值与销毁13.2拷贝控制和资源管理13.3交换操作13.4拷贝控制示例13.5动态内存管理类13.6对象移动13.6.1右值引用13.6.2移动构造函数......