[Tutor] Beginner-->conditional statements

Stephen Harris cyberdiction@hotmail.com
Tue, 27 Aug 2002 15:13:32 -0700


I went to your website and read a good part of your tutorial.
I had a question about the usage of '%' for MOD and then
its apparent different meaning in the next contiguous section.
However, my post to you from your website bounced as spam!
I posted to you rather than list because your website indicated to do so.
The difference is between: a and alan; crosswinds/net;  and bt/com

So by etc. does that include SF Fisherman's Wharf and Wax Museum?
Santa Cruz, is 90 miles south on Hwy 1 and is a scenic drive. It has a
Boardwalk(probably of dubious value to you) and a Greek Festival
Sept 6-8 which takes place near the downtown shopping mall.

Original message below:
Hi,

Thank you, I am finding your tutorial useful, but got stuck.

I dont understand how '%' used in this example is consistent with mod?
Perhaps you just meant it as a variable for numbers. I am confused with
the prior usage as a remainder.

>>> print 7%4
3

% is known as the modulus or mod operator and in other languages is often
seen as MOD or similar.

Experiment and you will soon get the idea.

>>>print 'The total is: ', 23+45
You've seen that we can print strings and numbers. Now we combine the two in
one print statement, separating them with a comma. We can extend this
feature by combining it with a useful Python trick for outputting data
called a format string:

>>> print "The sum of %d and %d is: %d" % (7,18,7+18)
{SH: This seems like a new usage? I'm not sure how to evaluate it?
I couln't come up with a pattern for understanding it from previous info}
In this command the format string contains '%' markers within it. The letter
'd' after the % tells Python that a 'decimal number' should be placed there.
The values to fill in the markers are obtained from the values inside the
bracketed expression following the % sign on its own.

There are other letters that can be placed after the % markers. Some of
these include:

%s - for string
%x - for hexadecimal number
%0.2f - for a real number with a maximum of 2 decimal places
%04d - pad the number out to 4 digits with 0's

Regards,
Stephen


----- Original Message -----
From: <alan.gauld@bt.com>
To: <cyberdiction@hotmail.com>; <tutor@python.org>
Sent: Tuesday, August 27, 2002 3:25 AM
Subject: RE: [Tutor] Beginner-->conditional statements


> > Also does anyone know of a tutorial(which dwells upon)
> > that covers those conditional statements in some detail
> > with some graduating problems and solutions?
>
> Most of the tutorials on the beginners pages explain them.
> How much they provide in the way of excercises is variable.
>
> Have you looked at any of those tutorials yet? Is there
> anything specific you don't understand? (This is a
> good place to ask those kind of specific questions!)
>
> Alan g.
> Author of the 'Learning to Program' web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>