条件和循环
1、if语句
>>> if exception:
... expr_true_suite
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'exception' is not defined
>>> if not warn and (system_load >= 10):
... print("warning:losing resources")
... warn += 1
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'warn' is not defined
2、else语句
>>> if expression:
... expr_true_suite
... else:
... expr_false_suite
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'expression' is not defined
>>> if passwad == user.passwad:
... ret_str = "password accepted"
... id = user.id
... valid = True
... else:
... ret_str = "invalid password entered try again!"
... valid = False
...
Traceback (most recent call last)
File "<stdin>", line 1, in <module>
NameError: name 'passwad' is not defined
3、elif语句
If 语句后最多只能有一个else语句,但是可以有任意数量的elif语句。
4、条件表达式
>>> x,y = 4,3
>>> if x < y:
... smaller = x
... else:
... smaller = y
...
>>> smaller
3
5、while语句
>>> count = 0
>>> while(count < 9):
... print("the index is:",cou