赞
踩
如果我正确地理解了您的问题,您只需在参数中添加空格到raw_input或print:#create function
def list_sum(num_list):
#calculate and print out the sum of numbers
the_sum = 0
for i in num_list:
the_sum = the_sum + i
return the_sum
#accept 3 numbers and store them in variables
input_1 = float(raw_input("Input a number: "))
input_2 = float(raw_input("Input a second number: "))
input_3 = float(raw_input("Input the last number: "))
#take list of inputs
list_of_inputs = [input_1, input_2, input_3]
#calculate and print out the sum of numbers
sum_of_input = list_sum(list_of_inputs)
print("The sum: {:6.2f}".format(sum_of_input))
#calculate and print out the average of the numbers
the_average = (sum_of_input)/(len(list_of_inputs))
print("The average: {:6.2f}".format(the_average))
#calculate and print out the percent of the total that each number represents
for input_in_list in list_of_inputs:
percent_total = input_in_list/sum_of_input
print("The percent of the total of each number: {:6.2f}".format(percent_total))
输出
^{pr2}$
您已经完成了大部分工作,指定小数点后的2位数字。我还添加了一些随机的总宽度(6)到格式说明符。这个宽度包括小数点前的位数,小数点本身,以及后面的位数。在
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。