操作列表

第四章 操作列表

#4-1披萨
pizzas = ['new york style','chicago style','california style','pan pizza']
for pizza in pizzas:
    print("I like " + pizza.title() + " pizza!")
print("I really love piaaz!")
I like New York Style pizza!
I like Chicago Style pizza!
I like California Style pizza!
I like Pan Pizza pizza!
I really love piaaz!
#4-2动物
anmals = ['dog','cat','sheep','cow']
for anmal in anmals:
    print("A " + anmal + " would make a great pet!")
print("Any of these anmals woule make a great!")
A dog would make a great pet!
A cat would make a great pet!
A sheep would make a great pet!
A cow would make a great pet!
Any of these anmals woule make a great!
#4-3数到20
for num in range(1,21):#忘记冒号
    print(num)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#4-4一百万
numbers = list(range(1,10))
for num in numbers:
    print(num)
    
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#4-5计算1-100000的总和
nums = list(range(1,100000))
print(sum(nums))
print(max(nums))
print(min(nums))
4999950000
99999
1
#4-6奇数
nums = list(range(1,20,2))
for num in nums:
    print(num)
1
3
5
7
9
11
13
15
17
19
#4-7 3的倍数
numbers = list(range(3,30,3))
print(numbers)
[3, 6, 9, 12, 15, 18, 21, 24, 27]
#4-9列表解析
cube = [value**3 for value in range(1,11)]  #shilezhi**3
print(cube)
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
#4-8,liang
cubes = []
for value in range(1,11):
    cube = value**3
    cubes.append(cube)
print(cubes)
    
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
#4-10切片
nums = list(range(1,20,2))
for num in nums:
    print(num)
print("The first three items in the list are:" )#类型不同,可以考虑format
print(nums[0:3])
1
3
5
7
9
11
13
15
17
19
The first three items in the list are:
[1, 3, 5]
#4-11 4-12披萨列表复制  使用for循环
My_pizzas = ['new york style','chicago style','california style','pan pizza']
frind_pizzas = My_pizzas[:]
My_pizzas.append('cannoli')
frind_pizzas.append('ice cream')
print("My pizza are:")
for pizza in My_pizzas:
    print("\nMy pizza are:")
    print(pizza)
for pizzas in frind_pizzas:
    print("\nMy frind's pizza are:")
    print(pizzas)
My pizza are:

My pizza are:
new york style

My pizza are:
chicago style

My pizza are:
california style

My pizza are:
pan pizza

My pizza are:
cannoli

My frind's pizza are:
new york style

My frind's pizza are:
chicago style

My frind's pizza are:
california style

My frind's pizza are:
pan pizza

My frind's pizza are:
ice cream
#4-13自助餐
cafeterias = ('牛排','甜点','饮料','水果')
for cafeteria in cafeterias:
    print(cafeteria)
cafeterias = ('鸡排','咖啡','甜甜圈','柠檬汁')
for cafeteria in cafeterias:
    print(cafeteria)
牛排
甜点
饮料
水果
鸡排
咖啡
甜甜圈
柠檬汁

x 3 \sqrt[3]{x} 3x

1 x \frac{1}{x} x1

KaTeX parse error: Expected 'EOF', got '\sideset' at position 1: \̲s̲i̲d̲e̲s̲e̲t̲{^1_2}{^3_4}A

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值