[Tutor] Random in loop

2006-01-14 Thread ryan luna
Hello, Im kinda stuck on something in the book Python
Programming.
The "Challenage" is to make a progam that flips a coin
100 times and then tells you the number of heads and
tails.
here is what i have so far,
Code:

import random

coin = 0
heads = 0
tails = 0

heads_tails = random.randrange(2)

while coin < 100:
coin += 1
if (heads_tails == 0):
heads += 1
elif (heads_tails == 1):
tails += 1


print coin, heads, tails

raw_input("Enter to exit")

I know what my problem is, i just dont know the how to
fix it.
(Or i could just be writing this wrong all together)
If im even goin at this the right way my problem is i
need to randomly pick a new number at the beggening of
each loop but i dont know how! other then that i think
the rest of the code is good? Thanks for any help ^^
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random in loop

2006-01-14 Thread ryan luna

Thank you alot ^^ so simple and i knew it, but last
time i tried 
it i got an error on the =, most have been making a
stupid mistake
--- "ZIYAD A. M. AL-BATLY" <[EMAIL PROTECTED]> wrote:

> On Sat, 2006-01-14 at 17:52 -0800, ryan luna wrote:
> > Hello, Im kinda stuck on something in the book
> Python
> > Programming.
> > The "Challenage" is to make a progam that flips a
> coin
> > 100 times and then tells you the number of heads
> and
> > tails.
> > here is what i have so far,
> > Code:
> > 
> > import random
> > 
> > coin = 0
> > heads = 0
> > tails = 0
> > 
> > heads_tails = random.randrange(2)
> Why is the above line outside the loop?  Shouldn't
> you be flipping it a
> 100 times?  You're doing it once in this program. 
> (I think you know by
> know what you should do to correct this!)
> 
> > while coin < 100:
> > coin += 1
>  
> 
> 
> I hope this was helpful.
> Ziyad.
> 
> 

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


[Tutor] Strings backwards

2006-01-18 Thread ryan luna
Hello, what i need to do is get user input and then
print the string backwards ^^ i have no idea how to do
that, 

print "Enter a word and i well tell you how to say it
backwards"

word = raw_input("Your word: ")

print word

all that is simple enough im sure printing it out
backwards is to, just dont know how ^^, thanks for any help.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Jumble

2006-01-18 Thread ryan luna
Ok so what i have to do is make it so when a player
ask for a hint the program display a hint, heres my
loop, not whole script.

guess = raw_input("\nYour guess: ")
guess = guess.lower()
while (guess != correct) and (guess != ""):
print "Sorry, that's not it."
print "If you need a hint enter help"
if guess == hint:

The problem is its passing up "Hint" altogether
when the user input is hint it doesn't do anything,
prolly makin a noob mistake here, Thank for any help
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] yeah

2006-01-18 Thread ryan luna
Hi Hans and Adam,

Just wanted to point out: next time, let's try to
figure out why Ryan 
had
problems with this, rather than directly give a
working answer.

For example, we can ask things like: what part did
Ryan get stuck on?
Was it unfamiliarity with the things we can do with
slices, or 
something
else?  What did Ryan try?  What did Ryan look at?  Are
there programs 
that
Ryan has written that are similar to the one he's
asking about?

The reason for the caution is this: the reversal
question he asked felt
way too much like a homework exercise.  I hate being
pedantic, but it 
is
something we should be thinking about.

yeah, that was something i should know so i whent back
and read the whole chapter of the book that told me to
write such a program, the problem is i was out of it
when i read that part that nothing stuck, ^^
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Translator

2006-02-21 Thread ryan luna
Hello, this is just a simple things for a random
person im tryin to help out but it seems i got in
alittle over my head =P,
What i need is a program that translates english in-to
this completly made up language this person has.
The only way i can think of doin this seems...well
like a very bad way of doin it.
get the input from user then do alot of
if input == "a":
print "blah" for example
ect
I know there has to be a easier way, 
Any help? thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Translator

2006-02-21 Thread ryan luna
Well yeah its pretty basic, 
Just
*Example*
a = ba
just having a little trouble working out the code,
Still pretty new to python
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Translator

2006-02-22 Thread ryan luna
Well see, its not a complex language at all,
Here is basicly what it is
a = ba.
b = ga.
somthing like that, my only problem is getting it to
translate muiltpul letters at a time
say the user types a
it prints 
ba like it should,
but if the user types in ab
it prints ab
not baga
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Iron Python

2006-03-04 Thread ryan luna
Hello, i have a question about Iron Python, what
exactly does it do? i know its something about .net
but i still dont understand exactly what it does, To
use it do you still write your scripts in the Python
IDLE, or what 0-o,
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Pyexe

2006-03-04 Thread ryan luna
Hello, Call me a complete n00b but i dont understand
how to get Pyexe to work,
Iv read the site and kinda just confuses me, as you
can prolly tell im still pretty new to programming,
What exactly do i have to do with pyexe to make python
scripts exacutables.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Editing Pickled .dat files

2006-03-04 Thread ryan luna
Hello, this is like my 3rd question today lol which is
making up for not asking any for months =P, anyways
I have a pickled .dat file named dictionary, maybe
youv guessed this but its a dictionary of the
Alphabet, the program is a translator right now all it
does is translate the Alpabet (its a stupid made up
language helping someone out cuz i needed a project)
anyways im pretty sure i have the reading the pickled
file, taking input from the user, looking on the word
in the .dat file and printing out the translation, 
Here is where im stuck.
I want the program to be able to translate full words
to (the only way i know to do that is to put every
word in the dictionary, aka .dat file)
im not goin to put all the english words and there
translation in there myself! so i have a option for
the user to put there own definitions,
What i need to know is how do i take input from the
user, collect the word and its definitions and then
pickle it into the .dat but editing the dictionary in
the .dat file.
heres my code for reading so you get a better idea of
what i mean

pickle_file = open("dictionary.dat", "r")
dictionary = cPickle.load(pickle_file)
while sentence != "0":
sentence = raw_input("\nInput a english
letter/word to be translated: ")
if sentence in dictionary:
definition = dictionary[sentence]
print "\n", definition

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


Re: [Tutor] Editing Pickled .dat files

2006-03-04 Thread ryan luna
Hey, thanks for the help but when i try i get a error
Bad file descripter, here is the code im using

elif choice == "2":
pickle_file = open("dictionary.dat", "a")
sentence = raw_input("Enter the word youd like
to add: ")
if sentence not in pickle_file:
definition = raw_input("Whats the
translated version: ")
pickle_file[sentence] = definition
print "\n\t'",sentence,"'", "Has been
added to the dictionary."
else:
print "\n\tThat term already exists!"

--- Liam Clarke <[EMAIL PROTECTED]> wrote:

> Hi Ryan,
> 
> Technically, you don't.
> 
> You haul your dictionary out, as you're doing here -
> 
> dictionary = cPickle.load(pickle_file)
> 
> And when you're finished, you pickle it again.
> 
> Regards,
> 
> Liam Clarke
> 
> On 3/5/06, ryan luna <[EMAIL PROTECTED]> wrote:
> > Hello, this is like my 3rd question today lol
> which is
> > making up for not asking any for months =P,
> anyways
> > I have a pickled .dat file named dictionary, maybe
> > youv guessed this but its a dictionary of the
> > Alphabet, the program is a translator right now
> all it
> > does is translate the Alpabet (its a stupid made
> up
> > language helping someone out cuz i needed a
> project)
> > anyways im pretty sure i have the reading the
> pickled
> > file, taking input from the user, looking on the
> word
> > in the .dat file and printing out the translation,
> > Here is where im stuck.
> > I want the program to be able to translate full
> words
> > to (the only way i know to do that is to put every
> > word in the dictionary, aka .dat file)
> > im not goin to put all the english words and there
> > translation in there myself! so i have a option
> for
> > the user to put there own definitions,
> > What i need to know is how do i take input from
> the
> > user, collect the word and its definitions and
> then
> > pickle it into the .dat but editing the dictionary
> in
> > the .dat file.
> > heres my code for reading so you get a better idea
> of
> > what i mean
> >
> > pickle_file = open("dictionary.dat", "r")
> > dictionary = cPickle.load(pickle_file)
> > while sentence != "0":
> > sentence = raw_input("\nInput a
> english
> > letter/word to be translated: ")
> > if sentence in dictionary:
> > definition = dictionary[sentence]
> > print "\n", definition
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 

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


Re: [Tutor] Editing Pickled .dat files

2006-03-04 Thread ryan luna
Ohhh ok i got it to work! but why isn't the change
permanent? it is "writing" to the file isn't it.

--- Liam Clarke <[EMAIL PROTECTED]> wrote:

> Hi Ryan,
> 
> You're trying to use your file, dictionary.dat like
> a dictionary data
> structure in Python.
> They don't work the same way.
> 
> So.
> 
> pickle_file = open("dictionary.dat", "r")
> dictionary = cPickle.load(pickle_file)
> pickle_file.close()
> 
> elif choice == "2":
>  pickle_file = open("dictionary.dat", "a")
> sentence = raw_input("Enter the word youd
> like to add: ")
> if sentence not in dictionary:
>  definition = raw_input("Whats the
> translated version: ")
>   dictionary[sentence] = definition
>  print "\n\t'",sentence,"'", "Has been
> added to the dictionary."
>  else:
>  print "\n\tThat term already exists!"
> 
> 
> Once you're done, you just "repickle" the
> dictionary.
> 
> pickle_file = open("dictionary.dat", "w") #Opened in
> write mode
> cPickle.dump(dictionary, pickle_file)
> pickle_file.close()
> 
> Regards,
> 
> Liam Clarke
> 

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


[Tutor] Delete in .dat

2006-03-04 Thread ryan luna
My question seems like itd be farly simple but i cant
seem to get it to work,
My .dat file is a dictionary and i need to be able to
only delete a single word and its definition,
heres what i have so far but it doesn't work.

pickle_file = open("dictionary.dat", "r")
dictionary = cPickle.load(pickle_file)
pickle_file.close()
sentence = raw_input("What definition would
you like to delete?: ")
if sentence in dictionary:
del dictionary[sentence]
print "\n\t", sentence, "Has been removed"
else:
print "\n\t", sentence, "That word is not
in the dictionary"
pickle_file = open("dictionary.dat", "w")
cPickle.dump(dictionary, pickle_file)
pickle_file.close()

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


[Tutor] Bug in python, or is it just 3am

2006-04-21 Thread ryan luna
Hey everyone, i believe i might have found a bug in
python? im not sure, heres a screen shot.
http://img151.imageshack.us/img151/4268/pythonbug8by.jpg
When i type
number + 1
and print it,
It adds one,
But when i use a number = number + 1
right after the value stays the same,
Now i thought that number = number + 1 just wasn't
vailed in python untill i tried it again and it
worked,
Is this a bug or im i just missing somthing,
Cause it is rather late.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Bug in python, or is it just 3am

2006-04-21 Thread ryan luna
HA! ignore me, im stupid, XD i knew i should have
waited untill morning =P,
No bug, the number = number was just point to the old
number which was one number lower,
sorry. night =P
Oh i see someone replied -_- sorry lol
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Livewires

2006-04-26 Thread ryan luna
Hey,
So i decided to check out this Livewires Modules, but
while running through the tutorial i run into a
problem,
When i was trying to do the graphics stuff,
when i try and use this code

circle(300,195, endpoints = ((280,180),(320,180)))

and i get this error

Traceback (most recent call last):
 File "(stdin)", line 1, in ?
 File
"D:\programfiles\python\livewires\beginners.py", line
527, in circle
   if r <0: raise ExVadParmaeters('negative
radius')
livewires.beginngers.ExBadParameters: negative radius


So im pretty new to this Livewires crap, which iv
said, so any help would be great.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Wiget

2006-06-29 Thread ryan luna
Hey everyone, im just learning to use Tkinter, and im trynig to write a"Guess my number" game program in widget forum but im having some problems,First heres the code im using,Button(self,   text = "Sumit",   command = self.number_anwser  ).grid(row = 4, column = 0, sticky = W)        self.response_txt = Text(self, width = 50, height = 5, wrap = WORD)    self.response_txt.grid(row = 5, column = 0, columnspan = 4)        def number_anwser(self):    guess =
 self.guess_ent.get()    guess = int(guess)    response = ""    tries = 1        if (guess < the_number):    response += "Higher"    tries += 1    elif (guess > the_number):    response += "Lower"    tries += 1    else:    tries = str(tries)    response += "Correct! that was my
 number, \n"    response += "You guessed it in just "    response += tries    response += " tries!"      self.response_txt.delete(0.0, END)    self.response_txt.insert(0.0, response)    the_number = random.randrange(100) + 1root = Tk()root.title("Guess my number GUI")app = Application(root)root.mainloop()The problem is at the end where i try and get the number of Tries the user has tried it would just reset everytime the button in clicked, so my question is how would i go about getting the number of times the button is clicked and the anwser is wrong.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] unbound method function()

2006-07-12 Thread ryan luna
I have two Classes, I have a method in the first class (using Pygame/livewires moduls)Class1(games.Sprite):       function1(self):That is being called by the second classClass2(games.Sprite):       function2(self):          Class1.function1()When the code runs i get this error"unbound method function() must be called with Class2 instance as first argument(got nothing instead)"Its weird (to me) b/c i have other methods calling methods from other classes just fine, but on this one method i get that error.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor