codecademy.com关于python的两道小程序
来源:互联网 发布:linux kasan 编辑:程序博客网 时间:2024/05/28 05:18
题目一:
Write a function, shut_down, that takes one parameter (you can use anything you like; in this case, we'd use s for string). The shut_down function should return "Shutting down..." when it gets "Yes", "yes", or "YES" as an argument, and "Shutdown aborted!" when it gets "No", "no", or "NO".
If it gets anything other than those inputs, the function should return "Sorry, I didn't understand you."
代码如下:
def shut_down(s): if s.lower()=="yes": return "Shutting down..." elif s.lower()=="no": return "Shutdown aborted!" else: return "Sorry, I didn't understand you."
或者
def shut_down(s): if s=="YES" or s=="Yes" or s=="yes": return "Shutting down..." elif s=="NO" or s=="no" or s=="No": return "Shutdown aborted!" else: return "Sorry, I didn't understand you."或者
def shut_down(s): if s in ["YES","Yes","yes"]: return "Shutting down..." elif s in ["NO","no","No"]: return "Shutdown aborted!" else: return "Sorry, I didn't understand you."
题目二:
This is a two-parter: first, define a function, distance_from_zero, with one parameter (choose any parameter name you like).
Second, have that function do the following:
Check the type of the input it receives.
If the type is int or float, the function should return the absolute value of the function input.
If the type is any other type, the function should return "Not an integer or float!"
代码如下:
def distance_from_zero(s): if type(s)==int or type(s)==float: return abs(s) else: return "Not an integer or float!"
- codecademy.com关于python的两道小程序
- 给大家推荐一个python的学习网站 http://www.codecademy.com
- CodeCademy | Python | 6. Pyglatin
- CodeCademy | Python | 7. Function
- python codecademy 学习2
- codecademy python lesson1
- codecademy python lesson2
- codecademy.com之JavaScript学习
- python基础资料(Learn|Codecademy好用的工具)
- 在codecademy上学习Python
- python学习笔记之codecademy
- codecademy
- [Unsolved] Bug Record in Codecademy.com
- [Unsolved] Bug Record in Codecademy.com
- learning python from codecademy: 1.python syntax
- 让你学的更多:编程学习网Codecademy又添Python
- Codecademy网学习Python第二天
- Codecademy网学习Python第三天
- Android MediaScanner 详尽分析
- iphone之使用讯飞语音sdk实现语音识别功能
- Flex通过IFrame嵌入html,并调用html中的js脚本
- HDU 1232(并查集)
- java桶排序
- codecademy.com关于python的两道小程序
- c++输入输出流格式控制
- 加入ddraw.lib库文件
- KMP
- eclipse部署项目到webapps下,如何不带contextPath来访问
- POCO库 Foundation::Thread模块 多线程与线程池支持
- iOS学习笔记05—数据持久化
- 牛腩新闻发布系统小结
- 用自己的域名访问web