Python if-elif-else
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'
Python if-elif-else的更多相关文章
- python if elif else判断语句
username = 'jack' password = ' _username = input('username') _password = input('password') if userna ...
- python if elif else 区别
if data_ori=='医疗': # 医疗 df = pd.read_excel(path_apply + 'apply/YS_ZY_HZSQ_样例.xls', encoding='gbk', e ...
- python基础之条件控制与循环
Python3 条件控制 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户 ...
- Python基础s14-day1
2016年7月23日"Python基础s14-Day1" Python是什么? Python(英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/),是一种面向对象.直译式 ...
- <转>Python学习推荐
书籍推荐 基本了解: <<A Byte of Python>> (Python简明教程http://sebug.net/paper/python/) 网上有资源,两小时了解基本 ...
- ruby和Python简单对比
前不久学了ruby,发现ruby和Python非常像,于是自个测试对比了下,测完了才知道网上有现成的……下面是测试结果 序列(包括列表和元组等)有分片的特点:可能会比较方便的提取其中特定元素,暂时 ...
- Day2 Python的运算符及三大语句控制结构
Python的运算符 Python语言支持以下类型的运算符: 算术运算符 比较(关系)运算符 赋值运算符 逻辑运算符 位运算符 成员运算符 身份运算符 运算符优先级 Python的三大语句控制结构: ...
- python自动拉取备份压缩包并删除3天前的旧备份
业务场景,异地机房自动拉取已备份好的tar.gz数据库压缩包,并且只保留3天内的压缩包文件,用python实现 #!/usr/bin/env python import requests,time,o ...
- Python 条件控制
Python 条件控制 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: if 语句 Python中if语 ...
- Python之旅:流程控制
流程控制之if...else 每条if语句的核心都是一个值为True或False的表达式,这种表达式被称为条件测试. Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定 ...
随机推荐
- hdu 1540 Tunnel Warfare 线段数区间合并
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) P ...
- java 类的加载、连接和初始化
JVM和类 调用Java命令运行Java程序时,该命令将会启动一条Java虚拟机进程,不管该Java程序启动了多少条线程,创建了多少个变量,它们都处于该Java虚拟机进程里,共享该JVM进程的内存区. ...
- Android中getDimension,getDimensionPixelOffset和getDimensionPixelSize 区别
getDimension 获取某个dimen的值,如果是dp或sp的单位,将其乘以density,如果是px,则不乘 返回float getDimensionPixelOffset 获取某个dim ...
- python脚本3_输入若干个整数打印出最大值
#输入若干个整数,打印出最大值 # m = int(input('Input first number >>>')) while True: c = input('Input a n ...
- 更改当前启动项,开关Hyper-V
switch-HyperV.bat @echo off "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\ ...
- log4j文件的配置
public class TestLog4j { /** * 级别从大到小 * fatal * error * warn * info * debug * trace * * off:不打印任何信息! ...
- react: navigator
1.page js import React from "react"; import {Link} from "react-router-dom"; impo ...
- shfileoperation 删除文件 FileDelete(CString strName)
From:http://blog.csdn.net/lvwx369/article/details/41440883 注意:其中namePath 为全局变量 Cstring namePath; BOO ...
- 【MFC】vs2013_MFC使用文件之15.mfc 按钮CBitmapButton的使用
本文是基于对话框的 博文基于 无幻 的博文为基础写的 http://blog.csdn.net/akof1314/article/details/4951836 笔者使用mfc撑死2个星期,不过这是有 ...
- HDU - 5936: Difference(暴力:中途相遇法)
Little Ruins is playing a number game, first he chooses two positive integers yy and KK and calculat ...