TQC+ 程式語言 Python 3 _ 610 平均溫度

說明:
請撰寫一程式,讓使用者輸入四週各三天的溫度,接著計算並輸出這四週的平均溫度及最高、最低溫度。
提示:平均溫度輸出到小數點後第二位。


輸入與輸出會交雜如下,輸出的部份以粗體字表示
Alt text


程式碼:
tempLi = []

for i in range( 4 ):
    print( "Week {}:".format( i+1 ) )
    for j in range( 3 ):
        temp = eval( input( "Day {}:".format( j+1 ) ) )
        tempLi.append( temp )

print ( "Average: {:.2f}".format( sum( tempLi ) / len( tempLi ) ) )
print ( "Highest: {}".format( max( tempLi ) ) )
print ( "Lowest: {}".format( min( tempLi ) ) )

沒有留言:

張貼留言