Python Schleifen finden n als 101 statt 100, ich bekomme den Durchschnitt von 5050 als 50 statt 50,50, Was könnte das Problem sein? Wie soll ich es durchmachen? Hier ist meine Funktion.Python gefunden n als 101 statt 100
def sum_and_average(n):
total = 0
for i in range(1, n+1):
total += i
average = float(total/n)
print "the sum is %d and the average is %f" %(total, average)
sum_and_average(100)
Es gibt:
the sum is 5050 and the average is 50.000000
@ayhan okay Lass mich das versuchen .. danke. –