Python-如何将while循环转换为for循环?
count()itertools模块中的Usin函数提供了均匀间隔的值的迭代器。该函数有两个参数。start默认为0,step默认为1。使用默认值将生成无限迭代器。使用break终止循环。
import itertools
percentNumbers = [ ]
finish = "n"
num = "0"
for x in itertools.count() :
num = input("enter the mark : ")
num = float(num)
percentNumbers.append(num)
finish = input("stop? (y/n) ")
if finish=='y':break
print(percentNumbers)上面脚本的示例输出
enter the mark : 11 stop? (y/n) enter the mark : 22 stop? (y/n) enter the mark : 33 stop? (y/n) y [11.0, 22.0, 33.0]
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短