[Tutor] a neewbie at python

Magnus Lyckå magnus@thinkware.se
Thu May 8 15:39:01 2003


At 11:01 2003-05-08 +0200, Ellen wrote:
>Hello guys.
>I am a neewbie at python programming and I am also a first year student
>doing EEE103W and we use python.We were told to write a program`that
>works as a calculator which does simple arithmetic operations like
>+,%,/,* and -. The example our lecturer gave was that if we run our
>programme as python "name of programme" 23.4 + 17.5
>  the output shoud be 40.9.
>
>I have no idea what to do so can you please advise me guys coz I am
>afraid of failing my June exam as I have never done python before.
>Thank you,Ellen.

Hi Ellen, I'm sure you will be able to do that before June.
Python is something you learn in hours or days if you have
been programming in other languages before.

Sometimes the worst thing is to get started, but I think
you should start by playing a little with python. Probably
while reading one of the many tutorials. Then you should be
able to get a feeling for what Python can do, and then you
just solve the problem, a tiny step at a time... Don't let
it overwhelm you.

As usual in problem solving of some kind, it's a good
strategy to try to divide the problem into parts. In
your case, the obvious parts are 1) reading the command
line data into your program, 2) performing the calculation,
and 3) printing result. I think I'd do this in reverse
order in this case, first learn how to print out something,
then learn how to do basic calculations, and last learn how
to read input from the command line. Actually, I'd probably
begin with some very trivial version of the calculation,
and get that to work properly from command line to printed
output, and then, when that works, try to refine the
calculations so that they have all the features you need.

Actually, this *can* be written as only two lines of python
code, so it's not very advanced... (Actually, regarding the
two line version, it all depends on what you expect the
calculations to be like. It won't be able to give 5 as a
result if you type in "4 + 25%". That requires a few more
lines of code.)

Good Luck, and have fun with Python.


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program