[Tutor] raw_input into range() function

2007-04-18 Thread Guba

Hello,

I am trying to do the exercises in Michael Dawson's "Absolute Beginner"
book. In chapter four ("for Loops, Strings, and Tuples") one of the
challenges is: "Write a program that counts for the user. Let the user
enter the starting number, the ending number, and the amount by which to
count."

The code I have come up with so far is further below; basically my
problem is that I don't know how to feed the range() function with the
user-input numbers it expects.

Your help is highly appreciated!

Guba


# Counting Program
# 2007-04-18

# Welcoming the player
print "Hello, let me do some counting for you!"

# Telling the player what to do & assigning that info to variables.
start_num = int(raw_input("Please give me a starting number. "))
end_num = int(raw_input("Please give me an ending number. "))
interval = int(raw_input("By which amount am I to count? "))

start_num == 0
end_num == 1
interval == 2

print "Counting:"
for i in range(0, 1, 2):
print i


raw_input("\n\nHit Enter to exit.")







___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] my first project: a multiplication trainer

2008-03-14 Thread Guba
Hello everybody,

I want to create a simple multiplication trainer which quizzes me on the
multiplication table. All multiplication combinations should be asked
once, without repetition.

Here my pseudo code:

###

A = [1,2,3,4,5,6,7,8,9]
B = [1,2,3,4,5,6,7,8,9]

asked_questions = ()
false_answers = ()

#block 1
While tuple "asked_questions" contains less than 81 items:
Take one random item from A and one random item from B
If the question is NOT in "asked_questions":
Add question to tuple "asked_questions" 
Calculate the question and wait for user-input  
print the question # e.g.: 3x6=
If answer is false:
add question to the tuple "false_answers"
print: "You have answered all questions!"   

###


I would very much appreciate if you could comment on/criticise my pseudo
code. In particular: is my approach correct, or would it be more
sensible to first generate (or supply?) all possible questions and then
select the ready questions randomly?

So far I am not concerned about what to do with the tuple
"false_answers". This I worry about later.

Thanks for your help!

Guba


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] my first project: a multiplication trainer

2008-03-16 Thread Guba
Hello!

I like the idea of retaining my original questions by creating a proxy
list, but I wasn't able to understand (find) the proxy list:

Chris Fuller wrote:

> from random import choice

> questions = [ [i,j] for i in range(1,10) for j in range(1,10) ]
> false_answers = []
> 
> choices = range(len(questions))

This I don't understand: len(questions) simply gives 81;
range(len(questions)) counts them all up: 0,1,2...80.

> 
> while choices:
>proxyq = choice(choices)
here choice(choices) picks ONE item  out of choices (e.g. 56) and
assigns it to proxyq
>del choices[choices.index(proxyq)]
here the item (56) just assigned to proxyq gets removed from choices
(question: why not use pop() for these last two steps?)
> 
>q = questions[proxyq]
here q is assigned to item 56, i.e. [7, 3], out of questions (which
contains all 81 possible questions).

Now, because we are operating in a while loop, 81 item are generated and
 81 items are accordingly picked out of the questions list, all this
without repetition of items..

If I am right (am I?) with my interpretation, then I still don't
understand how/where we generated a proxy list... I think we are just
running a while loop without having generated a list out of its ouput!??

Cheers for a short comment!

Guba


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] my first project: a multiplication trainer

2008-03-17 Thread Guba
Dear Chris, list,

cheers for the great help: very valuable indeed.

Chris Fuller wrote:
##
for proxyq in choices:
   q = questions[proxyq]
   answer = raw_input('%dx%d = ' % tuple(q))

   if int(answer) == q[0]*q[1]:
  print 'correct'
   else:
  print 'incorrect'
  false_answers.append(q)
##

I was unable to find information on tuple(). (The Python help function
was rather conservative in its output, Google not helpful).
What exactly is the use of tuple(q) here, and why does not a simple q
instead of tuple(q) do? The latter would have been my intuitive
expectation...

The other thing I have on my mind is this: how could I have the program
ask the math questions not horizontally but vertically? An example:

 4
x7
=

instead of

4x7=

Thank you all,

Guba

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question concerning Boolean operators

2008-03-20 Thread Guba
Dear list,

from Guido's tutorial:

It is possible to assign the result of a comparison or other Boolean
expression to a variable. For example,

>>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance'
>>> non_null = string1 or string2 or string3
>>> non_null
'Trondheim'

How does this work?? How does Python know that we are looking for
non_null? After all, we don't provide this information here, right? (I
take non_null is a variable.)
I must be missing something... Can anyone help?

Many thanks,

Guba

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Newbie question concerning text covering multiple lines

2007-04-04 Thread Guba Castro
Hello,

I recently started teaching myself Python with Michael Dawson's 'Python
Programming for the Absolute Beginner'.

My problem is that I am running Python 2.5 under Linux while the book is
based on Python 2.2.3. Apparently this means that I cannot just follow
the programming examples the author gives.

While I like the book and intent to continue using it, I was wondering
which online resources I should consult in order to bridge the gap. So
far I am stuck with the Python Tutorial at http://docs.python.org/tut/
which, however, doesn't care too precisely to my needs.

Would you happen to have any suggestions for me?

Many thanks,

Guba








___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: 
http://mail.yahoo.de
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor