Programming Tutorial for absolute beginners

  • Thread starter Clodoaldo Pinto
  • Start date
F

Frank Millman

Clodoaldo said:
This point is not easy to aproach. The fact is that it is necessary
that the beginner knows that there is a differerence between 3 / 2 and
3.0 / 2.

I don't want him to now about types, at least not at that stage. I used
the term "integer" for the lack of a better one and I didn't mention
"float". Any suggestions?

Regards, Clodoaldo.

Here is a idea. I am not sure if it is a good idea, but you can compare
it with the other suggestions for resolving this dilemma.

We know that Python is in the process of changing the division
operator. The main reason for the change is that the current approach
is not intuitive to a newcomer (whether experienced or not).

Why not think to the future, and do it like this. Instruct the reader
to enter 'from __future__ import division'. You do not have to explain
the details, just say that this is the way division will work in the
future, and this statement will eventually not be required.

Then your example will show that 3/2 = 1.5, which is what they would
expect.

Then you can mention that, if they just want the integer portion, they
can use int(3/2). I think that most people with the slightest
understanding of basic arithmetic will relate to this without a
problem.

My 2c

Frank Millman
 
C

Clodoaldo Pinto

Duncan said:
But as you use conversions to float in order to avoid integer division
in your code examples, it might be best to explain what's going on, even
if you do have to explain the relevant types.

I changed the comments in the first program that uses float() to:

# The raw_input() function asks the user for a text
# As a text can't be multiplied or divided the
# float() function tranforms the text into a decimal number

I can't imagine anyone (who doesn't already know) looking at the example
and not wondering why it returned 1 rather than something else.
....

Integer is more mathematical, and more precise. I just looked up some
definitions for "whole number", and found it can apparently mean
positive integer, non-negative integer, or integer. Maybe you can use
integer and just put "whole number" in brackets after it, the first time
you use it; as a vague definition? But describing the relevant types
and integer division might make your later examples clearer.

Now it says "integer (whole number)" followed by a link to a forum post
where this issue can be discussed.
http://programming-crash-course.com/integer_versus_float_division

Regards, Clodoaldo
 
C

Clodoaldo Pinto

Frank said:
We know that Python is in the process of changing the division
operator. The main reason for the change is that the current approach
is not intuitive to a newcomer (whether experienced or not).

Why not think to the future, and do it like this. Instruct the reader
to enter 'from __future__ import division'. You do not have to explain
the details, just say that this is the way division will work in the
future, and this statement will eventually not be required.

Then your example will show that 3/2 = 1.5, which is what they would
expect.

Then you can mention that, if they just want the integer portion, they
can use int(3/2). I think that most people with the slightest
understanding of basic arithmetic will relate to this without a
problem.
I included your suggestion in the forum topic that is linked from the
division paragraph:
http://programming-crash-course.com/integer_versus_float_division
 
J

John Salerno

Clodoaldo said:
I changed the comments in the first program that uses float() to:

# The raw_input() function asks the user for a text
# As a text can't be multiplied or divided the
# float() function tranforms the text into a decimal number

Hmmm, maybe a picky point for a newbie, but since there actually is a
decimal module now, you might want to change the description of float().
 
M

Marc 'BlackJack' Rintsch

Frank Millman said:
Why not think to the future, and do it like this. Instruct the reader
to enter 'from __future__ import division'. You do not have to explain
the details, just say that this is the way division will work in the
future, and this statement will eventually not be required.

Then your example will show that 3/2 = 1.5, which is what they would
expect.

Then you can mention that, if they just want the integer portion, they
can use int(3/2). I think that most people with the slightest
understanding of basic arithmetic will relate to this without a
problem.

Or instead of converting the `float` back to an `int`, they can use
integer division: ``3 // 2``

Ciao,
Marc 'BlackJack' Rintsch
 
F

Frank Millman

Marc said:
Or instead of converting the `float` back to an `int`, they can use
integer division: ``3 // 2``

I had thought of that. The reason I did not suggest it is that, as I
understand it, this tutorial is not about how to learn Python, it is
about teaching programming to the absolute beginner.

I imagine (hope I am not making invalid assumptions here) that Python
was chosen as a base because it is easy and intuitive to learn, and in
most cases it is. It just happens that division is one area where it is
a bit awkward.

The // syntax is specific to Python. I don't think you are helping the
absolute beginner by forcing them to understand what is going on here.
On the other hand, int(x) is a basic mathematical concept (extract the
portion to the left of the decimal point) that is shared by several
languages and is fairly easy to understand.

My 2c (I am up to 4c now)

Frank
 
C

Clodoaldo Pinto

Frank said:
I had thought of that. The reason I did not suggest it is that, as I
understand it, this tutorial is not about how to learn Python, it is
about teaching programming to the absolute beginner.

Right !!
I imagine (hope I am not making invalid assumptions here) that Python
was chosen as a base because it is easy and intuitive to learn, and in
most cases it is. It just happens that division is one area where it is
a bit awkward.

Right again !!

Although the Python way is almost always easy to learn I won't be
pythonic (as in specific to Python) where it won't help.

Regards, Clodoaldo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top