Discuss / Python / 循环作业

### 循环作业

Topic source

#### 小打小闹小情调123

#1 Created at ... [Delete] [Delete and Lock User]

#for 循环

for name in L:

print('Hello,',name)

#while 循环

i = 0

while i <= 2:

print('Hello, %s!'% L[i])

i = i + 1

#### 小打小闹小情调123

#2 Created at ... [Delete] [Delete and Lock User]

for循环程序有bug，名字后面没有打印出“!”

#for 循环

L = ['Bart', 'Lisa', 'Adam']
for name in L:
print('Hello, %s!' % name)


Hello, Bart!
Hello, Lisa!


M = ['Bart！', 'Lisa！', 'Adam！']


PS：尝试过list相加，但是list的加法机制和我想象的不一样。

L = ['Bart', 'Lisa', 'Adam']
S = ['!', '!', '!']
M = L + M
M


['Bart', 'Lisa', 'Adam', '!', '!', '!']


#### 小打小闹小情调123

#3 Created at ... [Delete] [Delete and Lock User]

L = ['Bart', 'Lisa', 'Adam']
for name in L:
name = name + '!'
print('Hello,', name)


#### 一殇然

#4 Created at ... [Delete] [Delete and Lock User]

for x in L:

print('Hello，',x,'!')

#### 小打小闹小情调123

#5 Created at ... [Delete] [Delete and Lock User]

#### 兔兔侠52093076

#6 Created at ... [Delete] [Delete and Lock User]

>>> L = ['Bart', 'Lisa', 'Adam']

>>> i=0

>>> while i<3:

L[i]='%s!' % L[i]

print(L[i])

i+=1

• 1