python基础学习02(if...else...elif)
来源:互联网 发布:怎么提高淘宝的转化率 编辑:程序博客网 时间:2024/06/07 05:09
if...else...elif
格式化打印
[root@node1 day1]# vi three.py
"""
#!/usr/bin/env python
name = raw_input('what is your name?:')
print 'Hello, %s where are you from?' % name
[root@node1 day1]# python three.py
what is your name?:wolf
Hello, wolf where are you from?
格式化输出
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
print 'Hello, %s ,you are %s years old, where are you from?' % name
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:22
Hello, wolf ,you are 22 years old, where are you from?
多行全部打印
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
age = raw_input('what is your job?')
msg = """
Information of %s as below:
Name : %s
Age : %s
Job : %s
""" %(name,name,age,job)
print msg
执行
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:22
what is your job?it loser
Information of wolf as below:
Name : wolf
Age : 22
Job : it loser
加判断时
#!/usr/bin/env python
name = raw_input('what is your name?:')
#int将字符串转换为数字
age = int(raw_input('how old are you?:'))
job = raw_input('what is your job?')
msg = """
Information of %s as below:
Name : %s
Age : %s
Job : %s
""" %(name,name,age,job)
#type查看字符类型
print type(age)
if age >=30:
print "You are too old, you can only work for ..."
else:
# pass
print 'you are still very young!'
print msg
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:49
what is your job?it
<type 'str'>
You are too old, you can only work for ...
Information of wolf as below:
Name : wolf
Age : 49
Job : it
加颜色
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
job = raw_input('what is your job?')
#有7中颜色 32是绿色
msg = """
Information of %s as below:
Name : \033[32;1m%s \033[0m;
Age : %s
Job : %s
""" %(name,name,age,job)
print type(age)
if int(age) >=30:
print "You are too old, you can only work for ..."
else:
# pass
print 'you are still very young!'
print msg
"three.py" 23L, 413C written
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:22
what is your job?it
<type 'str'>
you are still very young!
Information of wolf as below:
Name : wolf ;
Age : 22
Job : it
加背景
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
job = raw_input('what is your job?')
#42是背景
msg = """
Information of %s as below:
Name : \033[42;1m%s \033[0m;
Age : %s
Job : %s
""" %(name,name,age,job)
print type(age)
if int(age) >=30:
print "You are too old, you can only work for ..."
else:
# pass
print 'you are still very young!'
print msg
"three.py" 23L, 413C written
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:22
what is your job?it
<type 'str'>
you are still very young!
Information of wolf as below:
Name : wolf ;
Age : 22
Job : it
知识扩展:颜色和背景
多重判断
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
else:
job = raw_input('what is your job?')
msg = """
Information of %s as below:
Name : \033[42;1m%s \033[0m;
Age : %s
Job : %s
""" %(name,name,age,job)
print type(age)
if int(age) >=50:
print "You are too old, you can only work for ..."
elif int(age) >=30:
print "You are now in the middle age,so enjoy your life before getting too old...."
#最后一次判断按照逻辑不需要写条件了(逻辑很重要)
else:
# pass
print 'you are still very young!'
print msg
多重判断
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
job = raw_input('what is your job?')
msg = """
Information of %s as below:
Name : \033[42;1m%s \033[0m;
Age : %s
Job : %s
""" %(name,name,age,job)
print type(age)
if int(age) >=50:
print "You are too old, you can only work for ..."
elif int(age) >=30:
print "You are now in the middle age,so enjoy your life before getting too old...."
#elif int(age) >=20:
# print "You are young!!!"
else:
# pass
if int(age) >=20:
print 'you are still very young!'
else:
print 'you are not a adult!'
print msg
格式化打印
[root@node1 day1]# vi three.py
"""
#!/usr/bin/env python
name = raw_input('what is your name?:')
print 'Hello, %s where are you from?' % name
[root@node1 day1]# python three.py
what is your name?:wolf
Hello, wolf where are you from?
格式化输出
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
print 'Hello, %s ,you are %s years old, where are you from?' % name
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:22
Hello, wolf ,you are 22 years old, where are you from?
多行全部打印
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
age = raw_input('what is your job?')
msg = """
Information of %s as below:
Name : %s
Age : %s
Job : %s
""" %(name,name,age,job)
print msg
执行
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:22
what is your job?it loser
Information of wolf as below:
Name : wolf
Age : 22
Job : it loser
加判断时
#!/usr/bin/env python
name = raw_input('what is your name?:')
#int将字符串转换为数字
age = int(raw_input('how old are you?:'))
job = raw_input('what is your job?')
msg = """
Information of %s as below:
Name : %s
Age : %s
Job : %s
""" %(name,name,age,job)
#type查看字符类型
print type(age)
if age >=30:
print "You are too old, you can only work for ..."
else:
# pass
print 'you are still very young!'
print msg
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:49
what is your job?it
<type 'str'>
You are too old, you can only work for ...
Information of wolf as below:
Name : wolf
Age : 49
Job : it
加颜色
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
job = raw_input('what is your job?')
#有7中颜色 32是绿色
msg = """
Information of %s as below:
Name : \033[32;1m%s \033[0m;
Age : %s
Job : %s
""" %(name,name,age,job)
print type(age)
if int(age) >=30:
print "You are too old, you can only work for ..."
else:
# pass
print 'you are still very young!'
print msg
"three.py" 23L, 413C written
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:22
what is your job?it
<type 'str'>
you are still very young!
Information of wolf as below:
Name : wolf ;
Age : 22
Job : it
加背景
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
job = raw_input('what is your job?')
#42是背景
msg = """
Information of %s as below:
Name : \033[42;1m%s \033[0m;
Age : %s
Job : %s
""" %(name,name,age,job)
print type(age)
if int(age) >=30:
print "You are too old, you can only work for ..."
else:
# pass
print 'you are still very young!'
print msg
"three.py" 23L, 413C written
[root@node1 day1]# python three.py
what is your name?:wolf
how old are you?:22
what is your job?it
<type 'str'>
you are still very young!
Information of wolf as below:
Name : wolf ;
Age : 22
Job : it
知识扩展:颜色和背景
多重判断
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
else:
job = raw_input('what is your job?')
msg = """
Information of %s as below:
Name : \033[42;1m%s \033[0m;
Age : %s
Job : %s
""" %(name,name,age,job)
print type(age)
if int(age) >=50:
print "You are too old, you can only work for ..."
elif int(age) >=30:
print "You are now in the middle age,so enjoy your life before getting too old...."
#最后一次判断按照逻辑不需要写条件了(逻辑很重要)
else:
# pass
print 'you are still very young!'
print msg
多重判断
#!/usr/bin/env python
name = raw_input('what is your name?:')
age = raw_input('how old are you?:')
job = raw_input('what is your job?')
msg = """
Information of %s as below:
Name : \033[42;1m%s \033[0m;
Age : %s
Job : %s
""" %(name,name,age,job)
print type(age)
if int(age) >=50:
print "You are too old, you can only work for ..."
elif int(age) >=30:
print "You are now in the middle age,so enjoy your life before getting too old...."
#elif int(age) >=20:
# print "You are young!!!"
else:
# pass
if int(age) >=20:
print 'you are still very young!'
else:
print 'you are not a adult!'
print msg
0 0
- python基础学习02(if...else...elif)
- python基础--条件判断:if..elif..else
- Python基础篇之if-elif-else
- Python if elif else语句
- 【Python-2.7】if-elif-else
- python入门(三):条件判断 if elif else
- Python-if-elif-else语句
- python 流控制 if else, elif
- Python轻松入门-07 if elif else
- 0706学习笔记if, elif, else
- if-elif-else使用
- if-elif-else
- 2.8 python中的if...elif...else语句 [python入门教程]
- C语言基础- #if, #elif, #else, #endif 等的使用
- 关于python中的if-elif-else格式的问题
- Python 3基础教程8-if elif else语句
- C++ 学习系列(三) #if #elif #else 和 #endif指令
- python学习:if...else
- 控制台输出的内容复制到txt文件
- hibernate.hbm.xml 属性详解
- 在android studio 2.1 实现简单的ndk
- Mysql(一)安装使用
- [todo]scala之spray
- python基础学习02(if...else...elif)
- 使用缓冲输入流和缓冲输出流复制文件
- Codeforces 665B - Shopping
- [CODEVS1378]选课(树形dp)
- python基础学习03(循环)
- 教你HTML5与iOS交互实现各种排序动画演示
- Leetcode #57. Insert Interval 间隔插入 解题报告
- 网络--七层协议
- python颜色及背景