第二周作业

3-1 姓名:

代码:

names = ['Hong siyuan', 'lin dongwei', 'chen peipeng', 'li yinwei']
for name in names:
	print(name.title())

运行结果:


3-2 问候语:

代码:

names = ['Hong siyuan', 'lin dongwei', 'chen peipeng', 'li yinwei']
for name in names:
	print("Hello, " + name.title())

运行结果:


3-3 自己的列表:

代码:

transportions = ['Honda motorcycle', 'ship', 'car', 'bus']
for transportion in transportions:
	print("I would like to own a " + transportion + "!")

运行结果:


3-4 嘉宾名单:

代码:

names = ['Hong siyuan', 'lin dongwei', 'chen peipeng', 'li yinwei']
for name in names:
	print(name.title() + ", Would you ilke to have a dinner with me?")

运行结果:


3-5 修改嘉宾名单:

代码:

names = ['Hong siyuan', 'lin dongwei', 'chen peipeng', 'li yinwei']
for name in names:
	print(name.title() + ", Would you ilke to have a dinner with me?")
	
print("\n\n" + names[0].title() + " could not take part in this dinner.\n\n")
names[0] = "yang guidong"
for name in names:
	print(name.title() + ", Would you ilke to have a dinner with me?")

运行结果:


3-6 添加嘉宾:

代码:

names = ['Hong siyuan', 'lin dongwei', 'chen peipeng', 'li yinwei']	
for name in names:
	print(name.title() + ", Would you ilke to have a dinner with me?")


print("\n\nI find a larger dinner table!So I want more people to join in it!\n\n")


names.insert(0, "fang xiaona")
names.insert(2, "li huikeng")
names.append("huang jiahui")
for name in names:
	print(name.title() + ", Would you ilke to have a dinner with me?")

运行结果:


3-7 减缩名单:

代码:

names = ['Hong siyuan', 'lin dongwei', 'chen peipeng', 'li yinwei']	
for name in names:
	print(name.title() + ", Would you ilke to have a dinner with me?")

print("\n\nI find a larger dinner table!So I want more people to join in it!\n\n")

names.insert(0, "fang xiaona")
names.insert(2, "li huikeng")
names.append("huang jiahui")
for name in names:
	print(name.title() + ", Would you ilke to have a dinner with me?")

print("\n\nSorry, everyone!I only invite two people to join in it.\n\n")

while len(names) > 2:
	name = names[0]
	names.pop(0)
	print("I'm sorry, " + name.title() + ". I could not invite you to join in it.")
	
print("\n\n")
for name in names:
	print(name.title() + ", you're still in my list!")

del names[0]
del names[0]

print("\n\nThe list is ", names, ".")

运行结果:


3-8 放眼世界:

代码:

#coding:gbk
places = ['Beijing', 'Shanghai', 'Lundon', 'Paris', 'New York', 'Madrid']
#原始打印
for place in places:
	print(place)
#sorted打印
print("\n\n")
for place in sorted(places):
	print(place)
#原始打印进行检验顺序不变
print("\n\n")
for place in places:
	print(place)
#sorted,反向打印
print("\n\n")
for place in sorted(places, reverse=True):
	print(place)
#原始打印进行检验顺序不变
print("\n\n")
for place in places:
	print(place)
#反向打印	
print("\n\n")
places.reverse()
for place in places:
	print(place)
#再次反向打印	
print("\n\n")
places.reverse()
for place in places:
	print(place)
#sort打印	
print("\n\n")
places.sort()
for place in places:
	print(place)
#sort,反向打印	
print("\n\n")
places.sort(reverse=True)
for place in places:
	print(place)

运行结果:



3-9 晚餐嘉宾:

代码:

names = ['Hong siyuan', 'lin dongwei', 'chen peipeng', 'li yinwei']
for name in names:
	print(name.title())
	
print("\n\nThe number of the poeple i invited is " + str(len(names)) +".") 

运行结果:


4-1 披萨 :

代码:

pizzas = ['vegetable', 'fruit', 'mashroom']
for pizza in pizzas:
	print("I like " + pizza + " pizza.")
	
print("\nI really love pizza!")

运行结果:


4-2 动物:

代码:

animals = ['cat', 'dog', 'horse']
for animal in animals:
	print("A " + animal + " would make a great pet.")
	
print("\nAny of these animals would run")

运行结果:


4-3 数到20:

代码:

for number in range(1,21):
	print(number)

运行结果:


4-5 计算1~1000000的总和:

代码:

number = list(range(1,1000001))
print(min(number))
print(max(number))
print(sum(number))

运行结果:


4-6 奇数:

代码:

numbers = range(1, 20, 2)
for number in numbers:
	print(number)

运行结果:


4-7 3的倍数:

代码:

numbers = range(3, 31, 3)
for number in numbers:
	print(number)

运行结果:


4-8 立方:

代码:

numbers = range(1, 11)
cubes = [x**3 for x in numbers]
for cube in cubes:
	print(cube)

运行结果:


4-10 切片:

代码:

favorite_foods = ['pizza', 'falafel', 'carrot cake', 'cannoli', 'ice cream']
print(favorite_foods[:3])
print(favorite_foods[2:])
print(favorite_foods[1:4])

运行结果:


4-11 你的披萨和我的披萨 :

代码:

pizzas = ['vegetable', 'fruit', 'mashroom']
friend_pizzas = pizzas[:]
pizzas.append('fish')
friend_pizzas.append('beef')

print("my favorite pizzas are:")
for pizza in pizzas:
	print(pizza)
	
print("\nmy friend's favorite pizzas are:")
for pizza in friend_pizzas:
	print(pizza)

运行结果:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好!改善深层神经网络的方法有很多,以下是一些常见的方法: 1. 使用更好的激活函数:传统的激活函数如Sigmoid、tanh等可能存在梯度消失或爆炸的问题。可以尝试使用ReLU、Leaky ReLU、ELU等激活函数,以减轻这些问题。 2. 使用批标准化(Batch Normalization):批标准化对网络的输入进行标准化,有助于加快网络的训练速度,并且可以缓解梯度问题,使得更深层的网络也能够训练得更好。 3. 使用残差连接(Residual Connections):残差连接可以帮助信息在网络中更好地流动,从而减轻梯度消失的问题。通过将某些层的输出与输入相加,可以使得网络更易于训练。 4. 使用更好的优化算法:传统的梯度下降算法如随机梯度下降(SGD)可能存在训练速度慢、易陷入局部最优等问题。可以尝试使用更高级的优化算法如Adam、RMSprop等,以加快模型的收敛速度。 5. 添加正则化:过拟合是深层神经网络常见的问题之一。可以通过添加正则化项如L1正则化、L2正则化等来限制模型的复杂度,防止过拟合的发生。 6. 数据增强:通过对训练数据进行一些随机的变换,如平移、旋转、缩放等,可以增加模型的泛化能力,防止过拟合。 这些方法只是改善深层神经网络的一部分,具体的选择和调整需要根据具体问题和数据集来进行。希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值