[Tutor] new on the list
Alan Gauld
alan.gauld at btinternet.com
Thu Feb 28 10:51:22 CET 2008
<tonytraductor at linguasos.org> wrote
> This is my first post to this list.
Welcome Tony.
> I started learning to write bash scripts in November, first,
> and started learning Tcl in January
Good starts, although Python is a little different to Tcl its
generally easier to read. But their capabilities are similar.
> I've played a little with java, but haven't really
> gotten beyond "Hello, World!", same with C.
Compiled languages take a bit more getting used to,
especially since both C and Java require more detailed
work from the programmer.
> from random import randint
>
> ing = ("pepperoni", "ham", "onions", "sausage", "bacon", "peppers",
> "spiders", "mozzarella", "anchovies", "chocolate chips", "dog
> hairs", "toe-nail clippings", "fried clams", "lollipops", "paper
> clips", "calamari", "m&ms", "broccoli", "gum drops", "green beans")
>
> print "Let's make a pizza with"
>
> for i in range(5):
> p = randint(0,19) # someone told me I could have done len(ing), but
> I do not know what 'len' is yet.
len() is a general purpose function inPython that will tell you
the length of things. In this case it would tell you how many
items in your tuple ing. It can also tell you how many characters
in a string etc.
There are lots of other things in the random module you could have
used, including random.choice...
> He told me to write a program that would print 5 lines, like this:
> *
> **
> ***
> I thought this one was easy.
Me too...
> t = "*"
>
> for i in range(5):
> print t * (i+1)
> How'd I do?
OK, but its not really configurable so maybe you should read
the number of lines from the user somehow? Also you could
avoid the addition each time by moving it to the range function
for i in range(1, i+1):
print t * i
> (I wrote these using a simple text editor that I made with Tcl,
> too, http://www.linguasos.org/tcltext.html )
Fine but it will be easier to use a syntax aware full featured
editor like vim or Idle or emacs or Scite
But overall you are on the right lines.
--
Alan Gauld
Author of the Learn to Program web site
Temorarily at:
http://uk.geocities.com/alan.gauld@btinternet.com/
Normally:
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list