- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Solutions - Chapter 5
5-3: Alien Colors #1
Imagine an alien was just shot down in a game. Create a variable called?alien_color?and assign it a value of?green,?yellow, or?red.
Write an?if?statement to test whether the alien’s color is green. If it is, print a message that the player just earned 5 points.
Write one version of this program that passes the if test and another tha fails. (The version that fails will have no output.)
Passing version:
alien_color = green
if alien_color == green:
print(You just earned 5 points!)
Output:
You just earned 5 points!
Failing version:
alien_color = red
if alien_color == green:
print(You just earned 5 points!)
(no output)
5-4: Alien Colors #2
Choose a color for an alien as you did in Exercise 5-3, and write an?if-else?chain.
If the alien’s color is green, print a statement that the player just earned 5 points for shooting the alien.
If the alien’s coor isn’t green, print a statement that the player just earned 10 points.
Write one version of this program that runs the?if?block and another that runs the?elseblock.
if?block runs:
alien_color = green
if alien_color == green:
print(You just earned 5 points!)
else:
print(You just earned 10 points!)
Output:
You just earned 5 points!
else?block runs:
alien_color = yellow
if alien_color == green:
print(You just earned 5 points!)
else:
print(You just earned 10 points!)
Output:
You just earned 10 points!
5-5: Alien Colors #3
Turn your?if-else?chain from Exercise 5-4 into an?if-elif-else?cahin.
If the alien is green, print a message that the player earned 5 points.
If the alien is yellow, print a message that the player earned 10 points.
If the alien is red, print a message that the player earned 15 points.
Write three versions of this program, making sure each message is printed for the appropriate color alien.
alien_color = red
if alien_color == green:
print(You just earned 5 points!)
elif alien_color == yellow:
print(You just earned 10 points!)
else:
pr
您可能关注的文档
- 苏科版八年级上册第五章平面直角坐标系提优训练(二)(无答案).docx
- 二次函数周末提优练习题(一)(无答案).docx
- 第二章--老年护理相关理论--百度.ppt
- 高中历史 人民版 必修一 专题一第三课 君主专制政体的演进和强化 .pptx
- 北师大版九年级数学上册 3.2 用频率估计概率 同步测试试题(无答案).docx
- 人教A版高中数学必修三.2.1 古典概型课件.ppt
- 2020届中考地理复习知识要点和跟踪训练:极地地区.docx
- 2017翰林学校初二语文综合测试二答案页-.docx
- 冀少版七年级生物上册7.4.3线性动物和环节动物课件 .ppt
- 粤教版 信息技术 必修 3.1.2 日常文本信息的加工和表达.ppt
- 九年级化学第六单元《碳和碳的氧化物》测试试题(含答案).doc
- 中考数学三角形考点复习.docx
- 2019-2020河北省经安中学化学九年级下册每课经典题课件滚动小专题金属活动性顺序的探究和应用.ppt
- 人教版九年级物理16.1 电压同步练习题(含解析).docx
- 《温度》物态变化课件.ppt
- 八年级物理上册《测量平均速度》练习试题.docx
- 鲁教五四学制物理八年级上册第三章5. 光的色散.pptx
- 2020届九年级中考沪科版物理(遵义)复习课件:第1篇 专项集训1测量密度的技巧 .ppt
- 冀教版英语七年级上册:Unit 4 Food and restaurants. Lesson 19 教案设计.doc
- 2019-2020年秋季人教版本高中化学选修4第四章《电化学基础》考试测试卷.docx
文档评论(0)