猿问

如何将下边这段while改写?用Python。

i = 0

numbers = []


while i < 6:

    print "At the top i is %d" % i

    numbers.append(i)


    i = i + 1

    print "Number now: ", numbers

    print "At the bottom i is %d" % i


print "The numbers: "


for num in numbers:

    print num

  1. 如何将上边这段while代码改写成一个函数,将测试条件(i<10)中的10 换成一个变量。

  2. 用for loop和range重写一遍。

毛毛雨林527
浏览 1323回答 0
0回答
随时随地看视频慕课网APP

相关分类

Python
我要回答