教材第三章课后习题(部分)

时间:2023-02-10 14:02:45

代码:

#3.1
names = ['alan','jade','mike']
for i in names:
	print(i,end=" ")
print()

#3.2
for i in names:
	print(i+", are you ok?")
print()

#3.3
str3 = ['car','bike','bus']
for i in str3:
	print("I like "+ i + ".")
print()

#3.4
guests = ['alan','jade','mike']
for i in guests:
	print(i + ',welcome to have dinner.')
print()

#3.5
print("mike can't come.")
guests.remove("mike")
guests.append("kaka")
for i in guests:
	print(i + ',welcome to have dinner.')
print()

输出:

alan jade mike 
alan, are you ok?
jade, are you ok?
mike, are you ok?

I like car.
I like bike.
I like bus.

alan,welcome to have dinner.
jade,welcome to have dinner.
mike,welcome to have dinner.

mike can't come.
alan,welcome to have dinner.
jade,welcome to have dinner.
kaka,welcome to have dinner.