Discuss / Python / 打卡

打卡

Topic source

13个望辰

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

#for循环

# -*- coding: utf-8 -*-
L = ['Bart', 'Lisa', 'Adam']
for name in L:
  print('hello, %s!' % name)

#while循环

# -*- coding: utf-8 -*-
L = ['Bart', 'Lisa', 'Adam']
n=0
while n<=2:
  print('hello, %s!' % L[n])
  n=n+1

13个望辰

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

改成

while n<=len(L):

更好

丁轩2012

#3 Created at ... [Delete] [Delete and Lock User]
print('hello, %s!' % name)

请问大神,

%s!' % name这一段的意思,为何结果!会在name后面

一帆大湿

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

改成:

while n<=len(L):

是错的,因为len(L)=3

所以应该是:

while n<len(L):

这样代码的结果才是对的


  • 1

Reply