发布时间:2019-09-24 08:24:40编辑:auto阅读(2196)
if用于条件判断,如果满足条件就执行否则就继续直到结束,熟悉shell条件判断就觉得so easy
格式:
if condition1:
execute command
elif condition2:
execute command
else:
execute command
for n in condition:
execute command
if示例1: #基于windows版 python3.5
#!/usr/bin/env pyhon
# -*- coding: UTF-8 -*-
# authors: jack
age = 28
guess_num = int(input("INPUT YOUR GUESS NUM:"))
if guess_num == age:
print("Your guess right.GOOD!!!")
elif guess_num > age:
print("Your guess letter!")
else:
print("Your guess smaller!")if示例2:
#!/usr/bin/env pyhon
# -*- coding: UTF-8 -*-
# authors: jack
user = 'jack'
passwd = 'jack123'
username = input("username:")
password = input("password:")
if user == username and password == passwd:
print ("username is correct...,login success!!!")
else:
print("Invaild username or password error...")
for示例1:
#!/usr/bin/env pyhon
# -*- coding: UTF-8 -*-
# authors: jack
age = 28
for n in range(10):
if n < 3:
guess_num = int(input("INPUT YOUR GUESS NUM:"))
if guess_num == age:
print("Your guess right.GOOD!!!")
break #跳出整个loop
elif guess_num > age:
print("Your guess letter!")
else:
print("Your guess smaller!")
else:
print("too many attempts ...bye bye")
break
上一篇: CentOS7下部署Python3+Dj
下一篇: Python回顾与整理3:数字
51380
50855
41439
38233
32730
29633
28448
23357
23292
21624
1715°
2441°
2041°
1975°
2326°
2007°
2717°
4549°
4355°
3106°