I did everything that the tutorial told me to do and type and I dont know why its just not working this is the tutorial code example: and this is the example of my code which for some reason it wont work.
count = 0 sum = 0.0 number = 1 print("Enter 0 to exit the loop") while number != 0: number = float(input("Enter a number: ")) if number != 0: count = count + 1 sum = sum + number print("The average was:", sum / count)
and this is the example of my code which for some reason it wont work.
count = 0
sum = 0.0
number = 1
print("Enter 0 to exit the loop")
while number != 0:
number = float(input("Enter a number: "))
if number != 0:
count = count + 1
sum = sum + number
print("The average was: ", sum / count)
The only possible problem I see with you solution is indentation errors. The "if" in "if number != 0" needs to line up with "number" in "number = float(input("Enter a number: "))".
ReplyDeleteIndentation is crucial in Python programs, since it determines where the code blocks are.