chap4 条件

发布时间 2023-11-28 19:45:13作者: mmmxxxrrr

chap4 条件

1.if语句

if ():



···
<following_statement>
如果输入正确则会执行程序,否则不会执行if语句里的内容

if else语句

```
x=input("x=")
x=float(x)
print("hello")
if x<10:
   print("wahoo")
else:
   print("oh no")
print("goodbye")
```

if else有选择性 可以有嵌套

if-elif-else语句

```
print("hello")
if x < 10:
    print("wahoo")
elif x <=99:
    print("meh")
else:
    print("hahahaha")
print("goodbye")
```

if x<10为真会输出wahoo 如果x>10且<=99输出meh 否则输出hahahaha

match-case语句

```
def f(x):
    match x:
       case 400:
			return "A"
	   case 404:
			return "B"
       case 418:
            return "C"
       case_:
            return "not found"  
```

类似于switch-case语句