Python第三/第四章练习

第三、四章编程练习

3-1

name = ['William','Jack','Sherry','Ivy']
print(name)

3-2

name = ['William','Jack','Sherry','Ivy']
print(name[0] + 'How are you?')
print(name[1] + 'How are you?')
print(name[2] + 'How are you?')
print(name[3] + 'How are you?')

3-4

guest = ['William','Jack','Sherry','Ivy']
print(guest[0] + ' Welcome to the party!')
print(guest[1] + ' Welcome to the party!')
print(guest[2] + ' Welcome to the party!')
print(guest[3] + ' Welcome to the party!')

3-6

guest = ['William','Jack','Sherry','Ivy']
print(guest[0] + ' Welcome to the party!')
print(guest[1] + ' Welcome to the party!')
print(guest[2] + ' Welcome to the party!')
print(guest[3] + ' Welcome to the party!')
print("I have a bigger table!")
guest.insert("Washington",0)
guest.insert("Amy",1)
guest.append("Jimmy")
print(guest[0] + ' Welcome to the party!')
print(guest[1] + ' Welcome to the party!')
print(guest[2] + ' Welcome to the party!')
print(guest[3] + ' Welcome to the party!')
print(guest[4] + ' Welcome to the party!')
print(guest[5] + ' Welcome to the party!')
print(guest[6] + ' Welcome to the party!')

3-9

guest = ['William','Jack','Sherry','Ivy']
print(guest[0] + ' Welcome to the party!')
print(guest[1] + ' Welcome to the party!')
print(guest[2] + ' Welcome to the party!')
print(guest[3] + ' Welcome to the party!')
print('I have ' + len(guest) + ' guests.')

4-1

pizzas = ["Italy","Sausage","Beef"]
for pizza in pizzas
    print("I like " + pizza + " pizza.")
print("I love pizzas.")

4-3

for i in range(1,21)
    print(i)

4-6

num = list(range(1,20,2))
for i in num
    print(i)

4-7

num = list(range(3,31,3))
for i in num
    print(i)

4-9

a = list(range(1,11))
b = []
for i in a
    b.append(i**3)
for k in b
    print(k)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值