我对 python 很陌生,正在努力为一个类创建一个程序。我们应该记录一周内每天的降雪量,并将输入四舍五入到小数点后一位,我在下面做了:
def main():
print "~*~*~*~*~*~ SNOWFALL LOG ~*~*~*~*~*~"
snowFall = float (raw_input("Enter Snowfall for Day 1: "))
print "Snowfall for Day 1: ", ("%.1f" % snowFall)
snowFall = float (raw_input("Enter Snowfall for Day 2: "))
print "Snowfall for Day 2: ", ("%.1f" % snowFall)
snowFall = float (raw_input("Enter Snowfall for Day 3: "))
print "Snowfall for Day 3: ", ("%.1f" % snowFall)
snowFall = float (raw_input("Enter Snowfall for Day 4: "))
print "Snowfall for Day 4: ", ("%.1f" % snowFall)
snowFall = float (raw_input("Enter Snowfall for Day 5: "))
print "Snowfall for Day 5: ", ("%.1f" % snowFall)
snowFall = float (raw_input("Enter Snowfall for Day 6: "))
print "Snowfall for Day 6: ", ("%.1f" % snowFall)
snowFall = float (raw_input("Enter Snowfall for Day 7: "))
print "Snowfall for Day 7: ", ("%.1f" % snowFall)
main()
但是,在那之后,我们应该使用for
循环计算总降雪量和平均值。我知道命令str(command)
也以某种方式涉及,但我不知道如何。
我应该如何解决这个问题?