Python if-elif-else
2024-10-09 12:37:02
alien_color = ['green','yellow','red']
for color in alien_color:
if color == 'green':
print 'alien_color_%s: player to obtain five !'%color
elif color == 'yellow':
print 'alien_color_%s: player to obtain ten !' % color
else:
print 'alien_color_%s: player to obtain ten-five !' % color
try:
age = input('please value a integer:') #####input输入的是整数,raw_input输入的是字符串
if int(age) < 2:
print 'he is a baby!'
elif int(age) >= 2 and int(age) < 4:
print 'he is going!'
elif int(age)>= 4 and int(age) < 13:
print 'he is a teenager!'
elif int(age) >= 13 and int(age) < 65:
print 'he is a Middle-aged people!'
else:
print 'he is a old people!'
except:
print 'please value a integer!'
登录打招呼
user_name = ['admin', 'jack', 'bob', 'tom', 'mary']
for value in user_name:
value = raw_input('please value a user name:')
if value == 'admin':
print 'hello %s, would you like to see a status report?'% value
break
elif value not in user_name:
print 'error value'
break
else:
print 'hello %s, thank you for logging in again' % value
break
lists = [1,2,3,4,5,6,7,8,9]
for i in lists:
if i == 1:
print str(i) + 'st'
elif i == 2:
print str(i) + 'nd'
elif i == 3:
print str(i) + 'rd'
else:
print str(i) + 'th'
最新文章
- 关于replace()方法中第二个参数的转义问题
- mysql连接查询,封装mysql函数
- Flume
- iOS:JSON格式字符串转字典,字典转JSON格式字符串
- C#文件夹和文件操作
- 原创:cellmap 基站查询 for android
- R 网页数据爬虫1
- Git差异比对
- http://my.oschina.net/chinacion/blog/647641
- mysql 二进制安装文件 下载
- java基础知识回顾之javaIO类---FileWriter和FileReader
- Linux查看机器型号
- python+sqlite3
- OC中给我们提供的一个技术:谓词(NSPredicate).note
- Python学习—数据库篇之索引
- python基础面试常见题
- linux搭建PHP开发环境
- ajaxFileupload 多文件上传
- War Chess bfs+优先队列
- New Concept English Two 20 52
热门文章
- 理解Java中字符流与字节流的区别(转)
- 使用Mybatis时报错Invalid bound statement (not found):
- Java Redis Pipeline 使用示例
- C++(十五) — sizeof 运算符
- How to Fix “ShellExecute failed (2): Is this command correct?” on Notepad++
- 上传图片到阿里云oss
- 【spark】分区
- Spring:org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class
- jsp的运行内幕--Tomcat容器对自定义标签的解析过程
- win7 秘钥