第2章 控制流
一、elif
name = "tj" age = 10 if name == 'Alice': print('Hi, Alice.') elif age < 12: print('You are not Alice, kiddo.') else: print('You are neither Alice nor a little kid.')
二、while
while True: print('Who are you?') name = input() if name != 'Joe': continue print('Hello, Joe. What is the password? (It is a fish.)') password = input() if password == 'swordfish': break print('Access granted.')
三、for
import random as r
import sys
for i in range(10):
print(r.randint(1, 10))
sys.exit() # 结束程序

浙公网安备 33010602011771号