-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_if_else.py
More file actions
80 lines (69 loc) · 2.66 KB
/
Copy path2_if_else.py
File metadata and controls
80 lines (69 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#条件语句 只要返回值是bool值的,都可以作为条件语句
"""
if [条件]:
[执行语句]
else:
[执行语句]
注意,一定要有缩进,这样是用来判断这个语句是否属于if 或者else 语句的
"""
# mood_index=int(input("对象今天心情指数:"))
#
# if mood_index>=60:
# print("恭喜 今晚应该可以打游戏!!!去吧皮卡丘!!!")
# else:
# print("为了自个小命,还是别打了~~~")
#多条件/嵌套条件语句 if elif else
# weight=float(input("请输入您的体重(单位:kg):"))
# height=float(input("请输入您的身高(单位:m):"))
# BMI=weight/(height*height)
# print("您的BMI是"+str(BMI))
# if BMI<=18.5:
# print("此时BMI处于偏瘦范围")
# elif BMI<=25:
# print("此BMI处于正常范围")
# elif BMI<=30:
# print("此BMI处于偏胖范围")
# else :
# print("此BMI处于肥胖范围")
#逻辑运算 与 或 非 and or not(注意,not只能用1个)
#优先级 not and or 优先级依次下降
#列表 ——一种数据结构
shopping_list=["键盘","键帽"]
#列表是可变的(和其他的数据类型的一个显著不同),只需要通过以下操作:
shopping_list.append("显示器") #append是直接改变了列表
print(shopping_list) #打印出来是这个效果['键盘', '键帽', '显示器']
shopping_list.remove("显示器")
print(shopping_list)
#对于其他不可变的数据类型,需要借助一下方法进行变换
s="Hello"
print(s.upper()) #这是可以把原先的字符串每个字母全部变成大写
print(s) #但是字符串本身并没有变
s=s.upper()
print(s)
#除此之外,列表还有一些其他操作
l=len(shopping_list)
print(shopping_list[0])
listt=[]
listt.append("键盘")
listt.append("键帽")
listt.append("电竞椅")
print(listt)
listt.remove("键盘")
listt[0]="硬盘"
print(listt)
#python字典dict(可变) 用于储存键值对 key:value
# 注意,不能储存可变的数据类型(比如列表就不能存储在字典里面)
contacts={("小明",38):"1235678987"}
#嗨哟一个不可变但是很像列表的数据结构:元组 tuple 用圆括号
example_tuple=("小明","小李")
contacts["小明",47]="123989327957"
#可以查找一个键是否已经存在于这个字典里面
print(("小明",38) in contacts) #返回bool值
#要删除一个键值对
del contacts[("小明",38)] #注意如果对应的键不存在,就会报错
#查询功能
qu=input("请输入您想要查询的流行语:")
if qu in contacts:
print(contacts[qu])
else:
print("您查询的流行语暂未收入。")