正在加载图片...
上游充通大粤 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Sample Problem: Simple Statistics Let's review our code of average: average4.py 井 A program to average a set of numbers # Illustrates sentinel loop using empty string as sentinel def main(): sum 0.0 count =0 xStr raw input ("Enter a number (<Enter>to quit)>>" while xStr!="": x eval(xStr) sumsum x count count 1 xStr raw input ("Enter a number (<Enter>to quit)>>" print "\nThe average of the numbers is",sum count main ( 4Sample Problem: Simple Statistics Let‟s review our code of average: # average4.py # A program to average a set of numbers # Illustrates sentinel loop using empty string as sentinel def main(): sum = 0.0 count = 0 xStr = raw_input("Enter a number (<Enter> to quit) >> ") while xStr != "": x = eval(xStr) sum = sum + x count = count + 1 xStr = raw_input("Enter a number (<Enter> to quit) >> ") print "\nThe average of the numbers is", sum / count main() 4
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有