Python 官方文档:入门教程 => 点击学习
if用于条件判断,如果满足条件就执行否则就继续直到结束,熟悉shell条件判断就觉得so easy格式:if condition1: execute commandelif condition2: execute commandelse
if用于条件判断,如果满足条件就执行否则就继续直到结束,熟悉shell条件判断就觉得so easy
格式:
if condition1:
execute command
elif condition2:
execute command
else:
execute command
for n in condition:
execute command
#!/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
--结束END--
本文标题: python基础学习3_if_for
本文链接: https://lsjlt.com/news/192055.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0