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 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短