On Mar 3, 2015 1:49 PM, <chelse...@yahoo.com> wrote: > > i expected them to be the same because 10 plus 25 plus 25 divided by 3 is 60 and they both say that but the one that that says total=0. im just not sure how that changes the equation >
Please use "reply to all" in your email client. You might be getting confused because your mental model is of a formula and mathematics. In Python, unfortunately that's not what's happening. Instead, in a python program, a computation is a sequence of actions that changes the world. For example, total=total+10 In a Python program, this has the physical form of a mathematical equation , but it's not! It means the following sequence of steps: "1. Load the current value of the 'total' variable, 2. add ten to that value, and 3. store the result into the 'total' variable". For any of that to work, 'total' must already have some prior numeric value that you haven't shown us yet. Math variables don't directly have a notion of "prior" or change over time. But Python variables do. Note how different the meaning of the statement is from an equation of algebra. You have to be very careful because the notation used in certain programming languages looks superficially like math. Here, the notation is borrowed, but the meanings are different: programmers have gotten used to the different meaning of symbols like '='. There *are* good programming curricula where the programming language behaves like algebra (see http://bootstrapworld.org for example). But unfortunately it's not what you'll be doing in Python. > Sent from Windows Mail > > From: Danny Yoo > Sent: Tuesday, March 3, 2015 3:45 AM > To: chelse...@yahoo.com.dmarc.invalid > Cc: Tutor@python.org > > On Mon, Mar 2, 2015 at 10:22 PM, <chelse...@yahoo.com.dmarc.invalid> wrote: > > > > don't understand why these execute different things… > > > > > > > > > > total=total+10 > >>>> total=total+25 > >>>> total=total+25 > >>>> average=total/3 > >>>> total > > 110 > >>>> average > > 36.666666666666664 > > > In your first case, what's the value of 'total' *before* all the > things you've typed in? > > Can you say more why you expected to see the same result here as in > the next program? They do look textually different, so I'd expect > them to likely have a different meaning, so I'm confused as to what > your expectations are. Say more about why you expected them to be the > same, and maybe we can understand better. > > > > > > > total=0 > >>>> total=total+10 > >>>> total=total+25 > >>>> total=total+25 > >>>> average=total/3 > >>>> average > > 20.0 > > Your second case makes sense. 10 + 25 + 25 is 60, and if we divide 60 > by 3, the we'd expect the average to be twenty. > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor