Re: [Tutor] Copying a mutable

2011-06-07 Thread Nathan
unsubscribe


在 2011-06-08 07:11:33,"Walter Prins"  写道:
Hi,


2011/6/7 Válas Péter
Hi,

let X be a mutable container, such as dict/set/list=bytearray, and Y=X,
When I change X, Y will follow it, having always the same value, although 
id(X)!=id(Y).

That's not correct:

Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> x=[1,2,3]
>>> y=x
>>> id(x)
36115464L
>>> id(y)
36115464L
>>> x.append(4)
>>> id(x)
36115464L
>>> id(y)
36115464L
>>> x
[1, 2, 3, 4]
>>>

As you can see, x and y are references to the same object (e.g. with the same 
id.)

Regards

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Nathan
who can tell me how to unsubscribe the message.




At 2011-06-13 01:13:05,"Steven DAprano"  wrote:

>Ryan Strunk wrote:
>> Hi everyone,
>> I'm designing a timeline. When the user presses the right arrow, 0.1 is
>> added to the current position. The user can add events to the timeline, and
>> can later scroll back across those events to see what they are. But
>> something I absolutely don't understand is happening:
>> I used the program to place events at 1.1, 2.1, and 3.1. Here is the end of
>> the debug output for arrowing to 3.1 and placing the event:
>> position = 2.7
>> position = 2.8
>> position = 2.9
>> position = 3.0
>> position = 3.1
>> event placed.
>> Everything appears straight forward. 
>
>
>It only *appears* straight forward, it actually isn't. That's because 
>the printed output is rounded so as to look nice. Compare:
>
> >>> x = 1/10.0
> >>> print(x)  # displayed as nicely as possible
>0.1
> >>> print('%.25f' % x)  # display 25 decimal places
>0.155511151
>
>
>For speed and simplicity, floats are stored by the computer using 
>fractional powers of two. That's fine for numbers which are powers of 
>two (1/2, 1/4, 1/256, and sums of such) but numbers that humans like to 
>use tend to be powers of 10, not 2.
>
>Unfortunately, many common fractions cannot be written exactly in 
>binary. You're probably familiar with the fact that fractions like 1/3 
>cannot be written exactly in decimal:
>
>1/3 = 0.... goes on forever
>
>The same is true for some numbers in binary:
>
>1/10 in decimal = 1/16 + 1/32 + 1/256 + ...
>
>also goes on forever. Written in fractional bits:
>
>1/10 decimal = 0.00011001100110011... in binary
>
>Since floats can only store a finite number of bits, 1/10 cannot be 
>stored exactly. It turns out that the number stored is a tiny bit larger 
>than 1/10:
>
> >>> Fraction.from_float(0.1) - Fraction(1)/10
>Fraction(1, 180143985094819840)
>
>Rounding doesn't help: 0.1 is already rounded as close to 1/10 as it can 
>possibly get.
>
>Now, when you print the dictionary containing those floats, Python 
>displays (almost) the full precision:
>
> >>> print {1: 0.1}
>{1: 0.10001}
>
>
>In newer versions of Python, it may do a nicer job of printing the float 
>so that the true value is hidden. E.g. in Python 3.1 I see:
>
>
> >>> print({1: 0.1})
>{1: 0.1}
>
>but don't be fooled: Python's print display is pulling the wool over 
>your eyes, the actual value is closer to 0.10001.
>
>
>One consequence of that is that adding 0.1 ten times does not give 1 
>exactly, but slightly less than 1:
>
> >>> x = 0.1
> >>> 1 - sum([x]*10)
>1.1102230246251565e-16
>
>
>(P.S. this is why you should never use floats for currency. All those 
>missing and excess fractions of a cent add up to real money.)
>
>
>To avoid this, you can:
>
>
>* Upgrade to a newer version of Python that lies to you more often, so 
>that you can go on living in blissful ignorance (until such time as you 
>run into a more serious problem with floats);
>
>* Use the fraction module, or the decimal module, but they are slower 
>than floats; or
>
>* Instead of counting your timeline in increments of 0.1, scale 
>everything by 10 so the increment is 1.
>
>That is, instead of:
>
>2.0  2.1  2.2  2.3 ...
>
>you will have
>
>20  21  22  23  24  ...
>
>
>* Or you just get used to the fact that some numbers are not exact in 
>floating point.
>
>
>
>
>-- 
>Steven
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Calling Classes From Tkinter Radio Buttons

2012-04-08 Thread Nathan
I'm using Tkinter for a GUI for a program of mine, and I'm trying to
use radio buttons to select different functions, but it's not working
right at all. Originally, I had something like

class ClassOne(self):

def ___str___(self):
return "This is the base class."

class ClassTwo(ClassOne):

def __str__(self):
return "This is the derived class."

in, say, classes.py, and something like

import classes
from Tkinter import *

class Application(Frame):

def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.widgets()

LabelText = classes.ClassOne()

def widgets(self):
ClassLabel = Label(self, text = self.LabelText)
ClassLabel.grid()

root = Tk()
app = Application(root)
root.mainloop()

in, say, GUI.py. This works perfectly fine, but it only sets the label
as "This is the base class." What I'd like is a way to use radio
buttons to configure the text of ClassLabel so that the user can
choose between the two classes.

Currently, I'm trying changing GUI.py to something like:

import classes
from Tkinter import *

class Application(Frame):

def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.widgets()

LabelText = classes.ClassOne()
classes = ["ClassOne", "ClassTwo"]

def widgets(self):
self.variable = IntVar()
ClassLabel = Label(self, text = self.LabelText)
ClassLabel.grid(row = 0)
ClassOneButton = Radiobutton(self, text = "This selects the
base class.", variable = self.variable, value = 0, command =
self.ChangeClass)
ClassOneButton.grid(row = 1, column = 0)
ClassTwoButton = Radiobutton(self, text = "This selects the
derived class.", variable = self.variable, value = 1, command =
self.ChangeClass)
ResetButton = Button(self, text = "Reset the label", command =
self.ResetLabel)

def ResetLabel(self):
self.ClassLabel.configure(text = LabelText)

def ChangeClass(self):
self.selection = self.variable.get()  # This should get the
value of the selected radio button, right?
self.LabelText = self.classes[self.selection]() # LabelText
changes according to the radio button.

root = Tk()
app = Application(root)
root.mainloop()


... but when I run this, BOTH radio buttons are selected, and it still
just gives me the base class. What am I doing wrong? Is there a way to
first call a class with a radio button, and then reconfigure the label
with that class? Any help that can be offered is appreciated!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python for Absolute Beginners

2012-09-28 Thread Nathan
Which edition do you have? My copy mentions nothing about a companion
guide, so my guess is that you don't need it. That said, my copy also
doesn't send me to any sites for the exercises. Everything I need is right
in the book.
On Sep 28, 2012 7:30 AM, "Debbie Snowdon"  wrote:

> **
> Help! I'm into Chapter 2 in the Book by Michael Dawson - I cannot access
> the Companion Guide. Do I need it? Do I have to purchase it? How do I get
> it? The site he sends me to is very confusing.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Dynamic TKinter widgets?

2012-11-24 Thread Nathan
I'm working on a simple Tarot reading program in Python 2.7, and I'm having
a bit of trouble with some GUI abstract. (Sorry, no code in here.)

As of right now, all of the logic is working, and I can generate Tarot
spreads that tell me, in text, the role of each card "position", and what
card is in that position. For example, if I were to use a simple three-card
past/present/future spread, the output would be something like:

Past: Prince of Swords
Present: The Hermit
Future: Ten of Disks

What I'm trying to do now is add support for the card images. the problem
is, the program supports multiple types of spreads (two, so far, are
selectable), and they use different numbers of cards. It looks like I need
a variable number of widgets to display something like this. I'm not
entirely sure how I would handle something like that.

Right now, though, I do have two ideas that I would like to run by you
guys.

The first is to use one text widget-- as opposed to the one label widget
I'm currently using-- and embed the images where the card names would be. I
would have to try out some demos first, though, to see if I can otherwise
use text widgets just as label widgets.

The other idea, which seems much more cumbersome, is to create a dummy
frame widget, then a frame widget designed specifically for each type of
spread. The user selects the spread they want to use (Celtic Cross), and
the associated frame gets placed on the GUI.

What do you guys think? Is there a better way to deal (ha!) with this?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dynamic TKinter widgets?

2012-11-24 Thread Nathan
I did consider using a canvas widget, but it looks a bit intimidating right
now. I'm sure I'll get to it eventually.

I don't think I've heard of Pmw. I take it it's a module that has a
"Notebook" widget class?
On Nov 24, 2012 10:33 PM, "Chris Fuller" 
wrote:

> On Saturday 24 November 2012, Nathan wrote:
> > I'm working on a simple Tarot reading program in Python 2.7, and I'm
> having
> > a bit of trouble with some GUI abstract. (Sorry, no code in here.)
> >
> > As of right now, all of the logic is working, and I can generate Tarot
> > spreads that tell me, in text, the role of each card "position", and what
> > card is in that position. For example, if I were to use a simple
> three-card
> > past/present/future spread, the output would be something like:
> >
> > Past: Prince of Swords
> > Present: The Hermit
> > Future: Ten of Disks
> >
> > What I'm trying to do now is add support for the card images. the problem
> > is, the program supports multiple types of spreads (two, so far, are
> > selectable), and they use different numbers of cards. It looks like I
> need
> > a variable number of widgets to display something like this. I'm not
> > entirely sure how I would handle something like that.
> >
> > Right now, though, I do have two ideas that I would like to run by you
> > guys.
> >
> > The first is to use one text widget-- as opposed to the one label widget
> > I'm currently using-- and embed the images where the card names would
> be. I
> > would have to try out some demos first, though, to see if I can otherwise
> > use text widgets just as label widgets.
> >
> > The other idea, which seems much more cumbersome, is to create a dummy
> > frame widget, then a frame widget designed specifically for each type of
> > spread. The user selects the spread they want to use (Celtic Cross), and
> > the associated frame gets placed on the GUI.
> >
> > What do you guys think? Is there a better way to deal (ha!) with this?
>
> I think the usual procedure with something like this is a single Canvas
> widget.
>
> You could also use a Notebook with tabs disabled from Pmw or the like to
> implement multiple alternate Frames.  As you say, more cumbersome.
>
> Cheers
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dynamic TKinter widgets?

2012-11-25 Thread Nathan
On Nov 25, 2012 6:49 PM, "ALAN GAULD"  wrote:
>
> CC'ing the list...
>

Oops, my bad. I forget to hit Reply All.

>>
>> I know you can use images instead of text with Labels, like you can with
Buttons.
>> The advantage of a Text widget, in this case, is that you can use both
in the same widget.
>> That way, I don't need to worry about how widgets are displayed,
shuffled around, and
>> undisplayed during runtime. One widget should handle everything.
>>
> Don't get hung up on the number of widgets. In the scheme of things
widgets are not
> expensive. Create them as you need them, delete them when you are done.
Layout
> managers are there to manage the layout for you. if you can define the
layout in terms
> of a grid then you can fill the grid with blanks to hold the shape and
add/remove
> widgets as you like.
>
> If you use pack you can either force the containing frame to a fixed size
or allow it
> to grow/shrink with the widgets. Either approach can work.
>>
>> This is standard? That's interesting to know. The biggest issue I'm
having here is scalability.
>> Each new spread is going to need a new frame widget, which in turn will
need
>> (number of cards in spread)*2 more widgets.
>>
> But that's how many? If its getting up beyond a couple of thousand then
you might
> have a problem. If its less than a hundred its not an issue. In between
you might want
> to be a bit clever.

Well, that depends entirely on how many spreads I'll eventually have, and
the average number of cards per spread. Celtic Cross, for example, is a ten
card spread, so it needs 21 widgets by itself. A hundred widgets is reached
with just 10 spreads averaging 4.5 cards each. I expect, ultimately, to
have more than that.

>>
>> As noted above, the Text widget solution only needs one.
>>
> Actually it probably needs more. Each image is a widget too, so you just
organise
> the widgets inside a Text instead of inside a Frame or Canvas.

Is that how it works on the source level, or "under the hood"? The code
makes it look like I'm only writing one widget, with multiple text and
image elements within it, but perhaps I'm misunderstanding something.

The approach I'm taking now is a Label widget, containing a single string
constructed with elements from lists. I'm hoping that I can take the same
approach using a single Text widget, and just convert every other string
element from a filename to an image.

>All these things are
> just containers for more widgets. Frames are designed to hold widgets,
end of story.
> Text is designed to *display* images and text - usually within a Frame.
Canvas is
> designed to *display* images and graphics shapes. If you want your images
joined
> or surrounded by lines/circles etc then go with Canvas. If you need to
include
> explanatory text around the images use a Text. If you want to create a
reusable
> widget that you can use in multiple screens or hot swap with other
variants of
> the same go with a Frame and build a display widget hierarchy. If you
just want to
> display a bunch of images it doesn't matter much which one you pick.
>

Then it seems Text it is. Perhaps later in development, Frames and/or
Canvases might be appropriate for more complex designs.

> I repeat, don't sweat over the widget count, that's not usually an issue.
>
> Alan G.
>

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dynamic TKinter widgets?

2012-11-28 Thread Nathan
Okay, now I see what I was doing wrong. For some dumb reason, I had
forgotten that you can create a widget without assigning a variable. That
helps runtime widget creation a LOT.

The Frame idea I had was actually writing out one Frame per type of spread;
I would have had, for example, celtic_cross_frame,
past_present_future_frame, etc. Selecting a different spread would hotswap
one spread Frame out for a new one and configure the widgets already
hardcoded in the Frame.

Then I remembered that all I need to do to create a widget is simply call
it and add it to the layout, so I just created a single Frame and a loop
that adds a variable number of widgets. Now I just destroy that Frame (and
thus, the widgets it holds), recreate it, and repopulate it.

Which, re-reading this discussion, is probably what you meant by standard
practice.

Thanks for your help!
On Nov 25, 2012 8:10 PM, "Nathan"  wrote:

>
> On Nov 25, 2012 6:49 PM, "ALAN GAULD"  wrote:
> >
> > CC'ing the list...
> >
>
> Oops, my bad. I forget to hit Reply All.
>
> >>
> >> I know you can use images instead of text with Labels, like you can
> with Buttons.
> >> The advantage of a Text widget, in this case, is that you can use both
> in the same widget.
> >> That way, I don't need to worry about how widgets are displayed,
> shuffled around, and
> >> undisplayed during runtime. One widget should handle everything.
> >>
> > Don't get hung up on the number of widgets. In the scheme of things
> widgets are not
> > expensive. Create them as you need them, delete them when you are done.
> Layout
> > managers are there to manage the layout for you. if you can define the
> layout in terms
> > of a grid then you can fill the grid with blanks to hold the shape and
> add/remove
> > widgets as you like.
> >
> > If you use pack you can either force the containing frame to a fixed
> size or allow it
> > to grow/shrink with the widgets. Either approach can work.
> >>
> >> This is standard? That's interesting to know. The biggest issue I'm
> having here is scalability.
> >> Each new spread is going to need a new frame widget, which in turn will
> need
> >> (number of cards in spread)*2 more widgets.
> >>
> > But that's how many? If its getting up beyond a couple of thousand then
> you might
> > have a problem. If its less than a hundred its not an issue. In between
> you might want
> > to be a bit clever.
>
> Well, that depends entirely on how many spreads I'll eventually have, and
> the average number of cards per spread. Celtic Cross, for example, is a ten
> card spread, so it needs 21 widgets by itself. A hundred widgets is reached
> with just 10 spreads averaging 4.5 cards each. I expect, ultimately, to
> have more than that.
>
> >>
> >> As noted above, the Text widget solution only needs one.
> >>
> > Actually it probably needs more. Each image is a widget too, so you just
> organise
> > the widgets inside a Text instead of inside a Frame or Canvas.
>
> Is that how it works on the source level, or "under the hood"? The code
> makes it look like I'm only writing one widget, with multiple text and
> image elements within it, but perhaps I'm misunderstanding something.
>
> The approach I'm taking now is a Label widget, containing a single string
> constructed with elements from lists. I'm hoping that I can take the same
> approach using a single Text widget, and just convert every other string
> element from a filename to an image.
>
> >All these things are
> > just containers for more widgets. Frames are designed to hold widgets,
> end of story.
> > Text is designed to *display* images and text - usually within a Frame.
> Canvas is
> > designed to *display* images and graphics shapes. If you want your
> images joined
> > or surrounded by lines/circles etc then go with Canvas. If you need to
> include
> > explanatory text around the images use a Text. If you want to create a
> reusable
> > widget that you can use in multiple screens or hot swap with other
> variants of
> > the same go with a Frame and build a display widget hierarchy. If you
> just want to
> > display a bunch of images it doesn't matter much which one you pick.
> >
>
> Then it seems Text it is. Perhaps later in development, Frames and/or
> Canvases might be appropriate for more complex designs.
>
> > I repeat, don't sweat over the widget count, that's not usually an issue.
> >
> > Alan G.
> >
>
> Thanks!
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Simple Python Telnet Client (Help with Asynchronous IO)

2010-08-03 Thread Nathan Farrar
Hello All,

I'm attempting to write a simple telnet client.  Yes, I've been told that I
should be using twisted to do this.  I want to learn to do it myself first,
so that I can fully understand the concepts - then I will scrap it and
switch to using twisted.

When I started, I didn't realize there was such a thing as blocking IO.  I
assumed that if I put the read/write calls for stdio & the socket in
different threads all would be good.  I've been told that this is not the
case and that if I perform a blocking IO call in a thread (such as
sys.stdin.read()) it will halt the execution of all threads in the process.
I found an example that uses the select module to see if any data is
available from stdin before attempting to read ... and that this is the
asynchronous/non-blocking way to do it.  I've implemented this code, but I
can't figure out a similar way to do this with the socket.

Here's the code I've put together so far:

#!/usr/bin/env python

import collections
import os
import select
import socket
import sys
import termios
import tty
import threading

class InputThread(threading.Thread):
""" Read data from the stdin and place in the input buffer. """
def __init__(self, input_buffer):
threading.Thread.__init__(self)
self.input_buffer = input_buffer

def run(self):
self.old_settings = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin.fileno())

# prompt loop
try:
while True:
if select.select([sys.stdin], [], [], 0) == ([sys.stdin],
[], []):
self.input_buffer.append(sys.stdin.read())
print "> "
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN,
self.old_settings)

class DisplayThread(threading.Thread):
""" Check ouput buffer for data.  Print and data and flush buffer. """
def __init__(self, output_buffer):
threading.Thread.__init__(self)
self.output_buffer = output_buffer

def run(self):
while True:
while len(self.output_buffer) > 0:
output_data = self.output_buffer.pop()
print output_data,

class SocketThread(threading.Thread):
""" Check input buffer.  If data exists, send it to socket.  Read any
incoming data from socket and place it in output buffer. """
def __init__(self, input_buffer, output_buffer):
threading.Thread.__init__(self)
self.input_buffer = input_buffer
self.output_buffer = output_buffer

def run(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setblocking(1)
self.socket.connect(('nannymud.lysator.liu.se',2000))

while True:
while len(self.input_buffer) > 0:
input_data = self.input_buffer.pop()
self.socket.send(input_data, '\n')
self.output_buffer.append(self.socket.recv(1024))

self.sock.close()

def main():
""" Interactive, multithreaded network client written in python. """
print "Use 'quit' to exit client."

input_buffer = collections.deque()
output_buffer = collections.deque();

input_thread = InputThread(input_buffer)
input_thread.start()

display_thread = DisplayThread(output_buffer)
display_thread.start()

socket_thread = SocketThread(input_buffer, output_buffer)
socket_thread.start()

if __name__ == '__main__':
main()

Help sorting this out so that I can fully understand the concepts and get
this working would be greatly appreciated.  As I mentioned previously, I am
fully planning on scrapping this and rewriting it using twisted once I
understand the concepts and have a working prototype.  Thank you!

- F4RR4R

-- 
Science replaces private prejudice with publicly verifiable evidence.
- Richard Dawkins
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Scripting-Puzzle Pirates

2010-10-24 Thread Nathan Finney

Hey,
 
So I got bored of having to do a repeated task on this game, YPP Puzzle Pirates 
and I was wondering if it was possible to script it. My task would be to start 
at a dock, click on the port arrow, choose a ship (a different one each time 
and in order preferably), go to its hold, select materials to be moved and move 
them to a set ship (the same one each time), then return to the starting 
position.
 
If this is possible would I first need a set of the games coding (which uses 
javascript) to be obtained so it could be read and a script used upon it.
 
Thank you 
 
Yours faithfully,
Nathan Finney.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread nathan virgil
I'm experimenting with OOP using the Critter Caretaker script from Python
Programming for the Absolute Beginner as my basis. I've noticed that a
dictionary/function combo is a great way to handle menus, and so I've
adapted the menu to read as:


selection = raw_input("Choice: ")
choices = {"0":quit, "1":crit.talk, "2":crit.eat, "3":crit.play}
choice = choices[selection]
choice()

so that I can call methods from a dictionary, instead of having an
excruciatingly long if structure. Unfortunately, the problem I'm running
into with this is that I can't pass any perimeters through the dictionary. I
can't figure out how, for example, I could have an option that calls
crit.eat(2) and another that calls crit.eat(4). The only thing I can think
of is going back to the if structure, but my instinct tells me that this is
a Bad Idea. What can I do?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread nathan virgil
I'm not familiar with lambdas yet, and I don't think this book will
introduce me to them; they aren't listed in the index, anyway.

Adding a bunch of single-line functions would work, but I'm not sure how
much better that is then the if structure. I think it's what I'm going to go
with, anyway. At least until I can learn about lambdas, or even some other
solution.

On Tue, Feb 24, 2009 at 2:42 PM, Kent Johnson  wrote:

> On Tue, Feb 24, 2009 at 2:03 PM, nathan virgil 
> wrote:
> > I'm experimenting with OOP using the Critter Caretaker script from Python
> > Programming for the Absolute Beginner as my basis. I've noticed that a
> > dictionary/function combo is a great way to handle menus, and so I've
> > adapted the menu to read as:
> >
> >
> > selection = raw_input("Choice: ")
> > choices = {"0":quit, "1":crit.talk, "2":crit.eat, "3":crit.play}
> > choice = choices[selection]
> > choice()
> >
> > so that I can call methods from a dictionary, instead of having an
> > excruciatingly long if structure. Unfortunately, the problem I'm running
> > into with this is that I can't pass any perimeters through the
> dictionary. I
> > can't figure out how, for example, I could have an option that calls
> > crit.eat(2) and another that calls crit.eat(4). The only thing I can
> think
> > of is going back to the if structure, but my instinct tells me that this
> is
> > a Bad Idea. What can I do?
>
> You can define a function that does what you want:
> def eat2():
>  crit.eat(2)
>
> Then put eat2 in your dictionary:
> choices = { '2': eat2, ...}
>
> Alternately you can use lambda expressions to do the same thing
> without an explicit def:
> choices = { '2': lambda: crit.eat(2), ... }
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread nathan virgil
On Tue, Feb 24, 2009 at 6:50 PM, Alan Gauld wrote:

>
>
> Or you can build the param value into the dictionary:
>
> selection = raw_input("Choice: ")
> choices = {
> "0":(quit, None),
> "1":(crit.talk, "Hi there"),
> "2":(crit.eat, "Nuts"),
> "3": (crit.play, "Soccer")
> "4": (crit.play, "Baseball")}  # same func different param
> choice = choices[selection]
> choice[0](choice[1])
>

This actually suits my needs wonderfully. Thanks!


>
> I
>
>> can't figure out how, for example, I could have an option that calls
>> crit.eat(2) and another that calls crit.eat(4).
>>
>
> The question is where are the 2 and 4 coming from?
> You could read them from the user or a file in option 1 above
> or store them with the function under a different menu in option 2.
> Or of course you could just hard code them at call time...


>
> It depends how you want to use it...
>

The "critter" has attributes for hunger and boredom; if you do anything but
eat (for hunger) or play (for boredom), the attribute value goes up, and
affects the critter's mood. If you access the right method, the
corresponding attribute will go down by a certain value. As it is right now,
it only uses the default value, but I was thinking of having different
options for the method. Maybe the critter finds cabbage more tasty/filling
then lettuce, or maybe it prefers playing baseball over playing soccer. This
could be represented by having cabbage represented by crit.eat(4) and
lettuce by crit.eat(2). In this case, getting the perimeters directly from
the user would be a Very Bad Idea, but I'm sure there's some scenarios where
it wouldn't be.


>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> ___
> 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] Passing perimeters in dictionary values?

2009-02-24 Thread nathan virgil
Erm, it's still not working...

Whenever I try to use the talk method (which reports the mood, and doesn't
take parameters), it says I gave it too many parameters. Maybe it might help
if I posted the code in it's entirety


# Critter Caretaker
# A virtual pet to care for

class Critter(object):
"""A virtual pet"""
def __init__(self, name, hunger = 0, boredom = 0):
self.name = name
self.hunger = hunger
self.boredom = boredom

def __pass_time(self):
self.hunger += 1
self.boredom += 1

def __get_mood(self):
unhappiness = self.hunger + self.boredom
if unhappiness < 5:
mood = "happy"
elif 5 <= unhappiness <= 10:
mood = "okay"
elif 11 <= unhappiness <= 15:
mood = "frustrated"
else:
mood = "mad"
return mood

mood = property(__get_mood)

def talk(self):
print "I'm", self.name, "and I feel", self.mood, "now.\n"
self.__pass_time()

def eat(self, food = 4):
print "Brruppp.  Thank you."
self.hunger -= food
if self.hunger < 0:
self.hunger = 0
self.__pass_time()

def play(self, fun = 4):
print "Wheee!"
self.boredom -= fun
if self.boredom < 0:
self.boredom = 0
self.__pass_time()

def backdoor(self):
print "hunger:", self.hunger, "boredom:", self.boredom

def quit():
print "God-bye!"


def main():
crit_name = raw_input("What do you want to name your critter?: ")
crit = Critter(crit_name)

selection = None
while selection != "0":
print \
"""
Critter Caretaker

0 - Quit
1 - Listen to your critter
2 - Feed your critter
3 - Play with your critter
"""

selection = raw_input("Choice: ")
choices = {"0":(quit, None), "1":(crit.talk, None), "2":(crit.eat,
3), "3":(crit.play, 3), "Xyzzy":(crit.backdoor, None)}
if selection in choices:
   choice = choices[selection]
   choice[0](choice[1])


main()
("\n\nPress the enter key to exit.")
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Loop help

2009-08-16 Thread Nathan Wing
Hello All,I've been racking my brain trying to figure out, what I imagine to
be, a very simple problem.  I found the Intro to comp science MIT open
course (
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-00Fall-2007/CourseHome/index.htm)
and was working on the very first homework assignment.  I was successful in
problem one, but having a hard time with problem two.  Any help would be
greatly appreciated!

Regards,
Nathan

Here is the problem:

A wealthy donor has given MIT $500,000 to be used to pay the tuition of one
student every other year until the money runs out. Under the assumptions
that
a. The current annual tuition is $34,986 per year,
b. Tuition goes up at a rate of 4.1%/year, and
c. The principal will be invested so that it earns 5%/year,

solve the following problems:
1) Write a program that calculates and prints the total number of students
this gift will support and the tuition paid for the last student.
2)Write a program that calculates and prints the smallest gift (rounded to
the nearest $100) needed to support one student every other year for 100
years. In addition, print the number of iterations your program took to
arrive at the answer. Hint: you may want to use nested loops for this
problem.

my code that works for number 1:

#!/usr/bin/env python
#
#scholarship.py
#

#initialize values
year = 0
count = 0
money = 100.0 #fund amount
ctuition = 34986.0 #current tuition
rate = 1.041 # 4.1% annual increase on tuition
principle = 1.05 #5% annual interest accrued on fund

###calculations
while money > 0 and money >= ctuition: #while the fund has money and can
cover tuition
if year % 2 == 0: #if this is year 0 or every even year after year 0
money = money - ctuition
ftuition = ctuition
count += 1

ctuition = ctuition * rate
money = money * principle
year += 1

print "Total number of students aided: %d" % count
print "Tuition paid for final recipient: $%.2f" % ftuition
print 'Total number of years fund was operative: %s' % str(year + 1)


my code for number two (this code ends up looping and does not increment the
initial funding, as I had thought it would):

#!/usr/bin/env python
#
#scholarship2.py
#

###  initialize values

loop = 1
while loop is 1:

year = 0
count = 0
initmoney = 50.0 #initial funding
money = initmoney #fund amount
ctuition = 34986.0 #current tuition
rate = 1.041 # 4.1% annual increase on tuition
principle = 1.05 #5% annual interest accrued on fund


###  calculations
while money > 0 and money >= ctuition: # while the fund has money and
can cover tuition
if year % 2 == 0: # if this is year 0 or every even year after year
0
money = money - ctuition
ftuition = ctuition
count += 1
print "pass ", count

ctuition = ctuition * rate
money = money * principle
year += 1

if year == 100:
loop = 0
print "The total funding required to last 100 yrs: $%.2f" %
initmoney
print count
print year
else:
print 'restart with new funding'
initmoney += 100.0
year = 0
count = 0
ctuition = 34986.0
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with pexpect

2009-10-16 Thread Nathan Farrar
I'm trying to automate the collection of data to remote devices over
ssh via pexpect.  I had originally attempted (with limited success) to
use paramiko, however due to cisco's ssh implimentation I cannot send
mulitple commands over the same connection, which is absolutely
essential.  Therefore, I'm now attempting to use pexpect, but am
having trouble getting started.  I have a simple script, such as:

session = pexpect.spawn('ssh u...@host')
session.expect([pexpect.TIMETOUT, 'password:'])
session.send('password')
print session.read() # shouldn't this display the logon banner & command prompt?
session.close()

This code results in no output & a hanging window. What am I doing incorrect?

Additionally, I will need to add conditional pexpect statements, such
that when I execute a command I want to gather the output, however if
'--More--' is encountered (and it this can happen multiple times), I
want to send a newline character to the session and continue gathering
the output.

Thanks for the help!
Nathan

-- 
"The presence of those seeking the truth is infinitely to be preferred
to the presence of those who think they've found it."

–Terry Pratchett
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Pexpect maxread & searchwindowsize, timeout

2009-10-20 Thread Nathan Farrar
I haven't been able to find any real examples of pexpect usage, nor
documentation.  Just little bits here and there, so I'm kind of
struggling through.

I've got the follow bit of code I'm working with:

def main():
try:
print 'attempting to spawn connection ... '
session = pexpect.spawn('ssh usern...@x.x.x.x')
except:
print 'couldn\'t spawn connection ... '

print 'waiting for password prompt ... '
session.expect('password:')
print 'received password prompt ... '

try:
print 'attempting to send password ... '
session.sendline(password)
except:
print 'error sending password ... '

print 'waiting for command prompt ... '
session.expect(command_prompt)
print 'received command prompt ... '

try:
print 'attempting to issue \'show version\' command ... '
session.sendline([expect.TIMEOUT=1, 'show version'])
except:
print 'error issuing \'show version\' command ... '

print 'waiting for command prompt ... '
session.expect(command_prompt)
print 'received command prompt ... '

print 'attempting to print command results ... '
print session.before

print 'closing session ... '
session.close()

if __name__=='__main__':
main()

When I run this against a cisco device, it times out waiting for the
command prompt after issuing the show version command.  However, if I
change 'show version' to something like 'blah blah' it doesn't time
out, and I get the results of the command (an error message that is
much shorter in length).

I believe that the results of the show version command are simply too
large.  I think I may need to increase the size of maxread &
searchwindowsize & set the timeout to something lower than the
default, but I haven't been able to figure out how to do this
correctly yet.

Any help would be greatly appreciated.  I'm pulling my hair out.  Thank you.

-- 
"The presence of those seeking the truth is infinitely to be preferred
to the presence of those who think they've found it."

–Terry Pratchett
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pexpect maxread & searchwindowsize, timeout

2009-10-20 Thread Nathan Farrar
Thanks!  That solves my question about configuring the timeout value.
However - I still have the problem (I believe) that by default, I can
handle all the output.  When I issue the "show version" it fails, but
if I issue a command with less data returned it succeeds.

In the documentation I can see that pexpect uses a maxread and a
searchwindowsize value, but I'm not sure how to use them.

Any tips?  Thanks again.

On Tue, Oct 20, 2009 at 11:26 AM, vince spicer  wrote:
>
>
> On Tue, Oct 20, 2009 at 11:11 AM, Nathan Farrar 
> wrote:
>>
>> I haven't been able to find any real examples of pexpect usage, nor
>> documentation.  Just little bits here and there, so I'm kind of
>> struggling through.
>>
>> I've got the follow bit of code I'm working with:
>>
>> def main():
>>    try:
>>        print 'attempting to spawn connection ... '
>>        session = pexpect.spawn('ssh usern...@x.x.x.x')
>>    except:
>>        print 'couldn\'t spawn connection ... '
>>
>>    print 'waiting for password prompt ... '
>>    session.expect('password:')
>>    print 'received password prompt ... '
>>
>>    try:
>>        print 'attempting to send password ... '
>>        session.sendline(password)
>>    except:
>>        print 'error sending password ... '
>>
>>    print 'waiting for command prompt ... '
>>    session.expect(command_prompt)
>>    print 'received command prompt ... '
>>
>>    try:
>>        print 'attempting to issue \'show version\' command ... '
>>        session.sendline([expect.TIMEOUT=1, 'show version'])
>>    except:
>>        print 'error issuing \'show version\' command ... '
>>
>>    print 'waiting for command prompt ... '
>>    session.expect(command_prompt)
>>    print 'received command prompt ... '
>>
>>    print 'attempting to print command results ... '
>>    print session.before
>>
>>    print 'closing session ... '
>>    session.close()
>>
>> if __name__=='__main__':
>>    main()
>>
>> When I run this against a cisco device, it times out waiting for the
>> command prompt after issuing the show version command.  However, if I
>> change 'show version' to something like 'blah blah' it doesn't time
>> out, and I get the results of the command (an error message that is
>> much shorter in length).
>>
>> I believe that the results of the show version command are simply too
>> large.  I think I may need to increase the size of maxread &
>> searchwindowsize & set the timeout to something lower than the
>> default, but I haven't been able to figure out how to do this
>> correctly yet.
>>
>> Any help would be greatly appreciated.  I'm pulling my hair out.  Thank
>> you.
>>
>> --
>> "The presence of those seeking the truth is infinitely to be preferred
>> to the presence of those who think they've found it."
>>
>> –Terry Pratchett
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
> Looks like you are trying to end multiple commands to the sendline and not
> expect
> you can specify the timeout on the expect line
>
> try this code:
>
> #
>
> def main():
>    try:
>        print 'attempting to spawn connection ... '
>        session = pexpect.spawn('ssh usern...@x.x.x.x')
>    except:
>        print 'couldn\'t spawn connection ... '
>
>    print 'waiting for password prompt ... '
>    session.expect('password:')
>    print 'received password prompt ... '
>
>    try:
>        print 'attempting to send password ... '
>        session.sendline(password)
>    except:
>        print 'error sending password ... '
>
>    print 'waiting for command prompt ... '
>    session.expect(command_prompt)
>    print 'received command prompt ... '
>
>    try:
>        print 'attempting to issue \'show version\' command ... '
>        session.sendline('show version') #: send only command
>    except:
>        print 'error issuing \'show version\' command ... '
>
>    print 'waiting for command prompt ... '
>    session.expect(command_prompt, timeout=1) #: set the timeout here
>    print 'received command prompt ... '
>
>    print 'attempting to print command results ... '
>    print session.before
>
>    print 'closing session ... '
>    session.close()
>
> if __name__=='__main__':
>    main()
> #==
>
> Vince
>
>
>



-- 
"The presence of those seeking the truth is infinitely to be preferred
to the presence of those who think they've found it."

–Terry Pratchett
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] html scrapeing

2005-06-28 Thread Nathan Hughes
Hi,

Ive been looking for way to scrape the data from a html table, but dont know even where to start, or how to do..

an example can be found here of the table (
http://www.dragon256.plus.com/timer.html ) - i'd like to extract all
the data except for the delete column and then just print each row..

Can anyone help ? Tnx.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I make Python calculate square roots?

2005-07-02 Thread Nathan Pinno




  Hi all,Does anyone know how to make Python calculate square 
  roots?
   
  Thanks,
  Nathan Pinnohttp://www.npinnowebsite.ca/

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


[Tutor] How to get 4 numbers from the user in one line for easy comparision?

2005-07-02 Thread Nathan Pinno



I saw that great idea from Steven, and I appreciate it. I think it will 
work. Just need to figure out how to get 4 numbers from the player on one line 
for easy comparison, e.g. telling whether the number is correct position and 
number, incorrect position and correct number, or both are incorrect.
 
If anyone has any advice in how to code this, I will gladly appreciate the 
help.
 
Sorry if I seem like a newbie, but I am! :)
Nathan Pinnohttp://www.npinnowebsite.ca/

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


[Tutor] Is there a way to combine a request for numbers and letters?

2005-07-04 Thread Nathan Pinno



Hi all,
 
Is there a way to combine a request for numbers and letters (e.g. user id 
and passwords)?
 
Thanks,
Nathan Pinnohttp://www.npinnowebsite.ca/

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


Re: [Tutor] Is there a way to combine a request for numbers and letters?

2005-07-04 Thread Nathan Pinno




  Sorry,
   
  Just remembered that strings can include both letters and numbers. Case 
  closed.
   
  Nathan PinnoCrew, McDonalds Restaurant, Camrose, AB Canadahttp://www.npinnowebsite.ca/
  
- Original Message - 
From: 
Nathan 
Pinno 
To: tutor@python.org 
Sent: Monday, July 04, 2005 3:55 
PM
Subject: [Tutor] Is there a way to 
combine a request for numbers and letters?

Hi all,
 
Is there a way to combine a request for numbers and letters (e.g. user 
id and passwords)?
 
Thanks,
Nathan Pinnohttp://www.npinnowebsite.ca/




___Tutor 
maillist  -  Tutor@python.orghttp://mail.pythonorg/mailman/listinfo/tutor

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


[Tutor] What's wrong with this code?

2005-07-04 Thread Nathan Pinno




  What's wrong with this code? I'm using 2.2.3 if this helps.
   
  #This is for a password protected program to store passwords.
  password = "hello"print "The Password Program"print "Copywrite 
  2005. All Rights Reserved."printanswer = raw_input("What is the 
  password? ")while password != answer:    print "The 
  password is incorrect."def main_menu():    print "1) 
  Add a login info card"    print "2) Lookup a login info 
  card"    print "3) Remove a login info 
  card"    print "4) Print Login info 
  list"    print "5) Save login list"    
  print "6) Open Login list"    print "9) Exit"
   
  def load_login(site,filename):    in_file = 
  open(filename,"r")    while 
  1:    in_line = 
  in_file.readline()    if 
  len(in_file) == 
  0:    
  break    in_line = 
  in_line[:-1]    [site,id,passcard] 
  = string.split(in_line,",")    
  list[site] = id and passcard    
  in_file.close()    def 
  save_login(site,filename):    out_file = 
  open(filename,"w")    for x in 
  site.keys():    
  out_file.write(x+","+sites[x]+"\n")    
  out_file.close()    menu_choice = 0list = 
  {}print "Welcome to the second half of the program."print 
  main_menu()while menu_choice != 9:    menu_choice = 
  input("Choose an option: ")    if menu_choice == 
  1:    print "Add a login info 
  card"    site = raw_input("Site: 
  ")    id = raw_input("User ID: 
  ")    passcard = 
  raw_input("Password: ")    
  list[site] = id and passcard    elif menu_choice == 
  2:    print "Lookup a login info 
  card"    site = raw_input("Site: 
  ")    if 
  site.has_key(site):    
  print "The ID is: 
  ",id(site)    
  print "The password is: 
  ",passcard(site)    
  else:    
  print site," was not found."    elif menu_choice == 
  3:    print "Remove a login info 
  card"    site = raw_input("Site: 
  ")    if 
  sites.has_key(site):    
  del numbers[site]    
  else:    
  print site," was not found."    elif menu_choice == 
  4:    print "Login 
  Info"    for x in 
  site.keys():    
  print "Site: ",x," \tID: ",numbers[x]," \tPassword: 
  ",numbers[x]    
  print    elif menu_choice == 
  5:    filename = 
  raw_input("Filename to save: ")    
  save_login(list,filename)    elif menu_choice == 
  6:    filename == 
  raw_input("Filename to load: ")    
  load_login(list,filename)print "Have a nice day!"
  Thanks,
  Nathan PinnoCrew, McDonalds Restaurant, Camrose, AB Canadahttp://www.npinnowebsite.ca/

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


Re: [Tutor] What's wrong with this code?

2005-07-06 Thread Nathan Pinno
  Hi all,

  I meant to ask why the main part after the password is not working right. 
No one has answered that yet. When I run the code and try to load a file 
that has been saved, a TypeError appears. How do I fix the code so no more 
errors will show up. Here is the newest code so far:

  # This is the code for a password protected program to store passwords.
  password = "hello"
  print "The Password Program"
  print "Copywrite 2005. All Rights Reserved."
  print
  answer = raw_input("What is the password? ")
  while password != answer:
  print "The password is incorrect."
  answer = raw_input("What is the password? ")
  def main_menu():
  print "1) Add a login info card"
  print "2) Lookup a login info card"
  print "3) Remove a login info card"
  print "4) Print Login info list"
  print "5) Save login list"
  print "6) Open Login list"
  print "9) Exit"

  def load_login(site,filename):
  in_file = open(filename,"r")
  while 1:
  in_line = in_file.readline()
  if len(in_file) == 0:
  break
  in_line = in_line[:-1]
  [site,id,passcard] = string.split(in_line,",")
  list[site] = id and passcard
  in_file.close()

  def save_login(site,filename):
  out_file = open(filename,"w")
  for x in site.keys():
  out_file.write(x+","+sites[x]+"\n")
  out_file.close()

  menu_choice = 0
  list = {}
  print "Welcome to the second half of the program."
  print main_menu()
  while menu_choice != 9:
  menu_choice = input("Choose an option: ")
  if menu_choice == 1:
  print "Add a login info card"
  site = raw_input("Site: ")
  id = raw_input("User ID: ")
  passcard = raw_input("Password: ")
  list[site] = id and passcard
  menu_choice = input("Choose an option: ")
  elif menu_choice == 2:
  print "Lookup a login info card"
  site = raw_input("Site: ")
  if site.has_key(site):
  print "The ID is: ",id(site)
  print "The password is: ",passcard(site)
  else:
  print site," was not found."
  menu_choice = input("Choose an option: ")
  elif menu_choice == 3:
  print "Remove a login info card"
  site = raw_input("Site: ")
  if sites.has_key(site):
  del numbers[site]
  else:
  print site," was not found."
  menu_choice = input("Choose an option: ")
  elif menu_choice == 4:
  print "Login Info"
  for x in site.keys():
  print "Site: ",x," \tID: ",numbers[x]," \tPassword: 
",numbers[x]
  print
  menu_choice = input("Choose an option: ")
  elif menu_choice == 5:
  filename = raw_input("Filename to save: ")
  save_login(list,filename)
  menu_choice = input("Choose an option: ")
  elif menu_choice == 6:
  filename == raw_input("Filename to load: ")
  load_login(list,filename)
  menu_choice = input("Choose an option: ")
  print "Have a nice day!"

  Thanks for the input so far,
  Nathan Pinno

  - Original Message - 
  From: "Brian van den Broek" <[EMAIL PROTECTED]>
  Cc: 
  Sent: Tuesday, July 05, 2005 1:03 AM
  Subject: Re: [Tutor] What's wrong with this code?


  > Andre Engels said unto the world upon 05/07/2005 02:44:
  >>>From the program::
  >>
  >> answer = raw_input("What is the password? ")
  >> while password != answer:
  >> print "The password is incorrect."
  >
  > 
  >
  >> I think you intended to make it so that
  >> the program kept asking for passwords until the right one was given.
  >> This is done with:
  >> answer = raw_input("What is the password? ")
  >> while password != answer:
  >> print "The password is incorrect."
  >> answer = raw_input("What is the password? ")
  >
  >
  > A small thing, but I think that is better as:
  >
  > while True:
  >  answer = raw_input("What is the password? ")
  >  if password == answer:
  >  break
  >  print "The password is incorrect."
  >
  > It probably runs a bit slower, but who cares, as the bottleneck is in
  > the chair, not the chip. The advantage is that there is only one
  > statement of the prompt to alter if you wanted to change it later.
  >
  > But, I think this will be one where reasonable people can differ.
  > Andre's version does make the semantics of the loop somewhat more 
obvious.
  >
  > Best to all,
  >
  > Brian vdB
  >
  > 
  >
  >> Andre Engels
  >
  > 
  >
  >
  > ___
  > Tutor maillist  -  Tutor@python.org
  > http://mail.python.org/mailman/listinfo/tutor
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Why is this error showing up? (Original Message: (Tutor) What's wrong with this code?) Ignore previous post.

2005-07-06 Thread Nathan Pinno



Hi all,
 
Here's one of the messages that pops up:
 
Traceback (most recent call last):  File "D:\password.py", line 
77, in ?    filename == raw_input("Filename to load: 
")NameError: name 'filename' is not defined
 
Why is it popping up whenever I try to load a file?
 
Here's the latest code:
 
# This is the code for a password protected program to store 
passwords.password = "hello"print "The Password Program"print 
"Copyright 2005 Nathan Pinno."printanswer = raw_input("What is the 
password? ")while password != answer:    print "The 
password is incorrect."    answer = raw_input("What is the 
password? ")def main_menu():    print "1) Add a login 
info card"    print "2) Lookup a login info 
card"    print "3) Remove a login info 
card"    print "4) Print Login info 
list"    print "5) Save login list"    
print "6) Open Login list"    print "9) Exit"
 
def load_login(site,filename):    in_file = 
open(filename,"r")    while 
1:    in_line = 
in_file.readline()    if len(in_file) 
== 0:    
break    in_line = 
in_line[:-1]    [site,id,passcard] = 
string.split(in_line,",")    
list[site] = id and passcard    
in_file.close()    def 
save_login(site,filename):    out_file = 
open(filename,"w")    for x in 
site.keys():    
out_file.write(x+","+sites[x]+"\n")    
out_file.close()    menu_choice = "0"list = 
{}print "Welcome to the second half of the program."print 
main_menu()while menu_choice != "9":    menu_choice = 
raw_input("Choose an option: ")    if menu_choice == 
"1":    print "Add a login info 
card"    site = raw_input("Site: 
")    id = raw_input("User ID: 
")    passcard = raw_input("Password: 
")    list[site] = id and 
passcard    menu_choice = 
raw_input("Choose an option: ")    elif menu_choice == 
"2":    print "Lookup a login info 
card"    site = raw_input("Site: 
")    if 
site.has_key(site):    
print "The ID is: 
",id(site)    
print "The password is: 
",passcard(site)    
else:    
print site," was not found."    
menu_choice = raw_input("Choose an option: ")    elif 
menu_choice == "3":    print "Remove 
a login info card"    site = 
raw_input("Site: ")    if 
sites.has_key(site):    
del numbers[site]    
else:    
print site," was not found."    
menu_choice = raw_input("Choose an option: ")    elif 
menu_choice == "4":    print "Login 
Info"    for x in 
site.keys():    
print "Site: ",x," \tID: ",numbers[x]," \tPassword: 
",numbers[x]    
print    menu_choice = 
raw_input("Choose an option: ")    elif menu_choice == 
"5":    filename = 
raw_input("Filename to save: ")    
save_login(list,filename)    
menu_choice = raw_input("Choose an option: ")    elif 
menu_choice == "6":    filename == 
raw_input("Filename to load: ")    
load_login(list,filename)    
menu_choice = raw_input("Choose an option: ")print "Have a nice day!"
 
Anything else that needs addressing?
 
Thanks,
Nathan Pinnohttp://www.npinnowebsite.ca/

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


Re: [Tutor] Why is this error showing up? (Original Message: (Tutor) What's wrong with this code?) Ignore previous post.

2005-07-07 Thread Nathan Pinno
  Thanks Wolfram for help with that error.

  Here's another that popped up:

  Traceback (most recent call last):
File "D:\password.py", line 68, in ?
  for x in site.keys():
  AttributeError: 'str' object has no attribute 'keys'

  How to fix it?

  Thanks,
  Nathan Pinno
  - Original Message - 
  From: "Wolfram Kraus" <[EMAIL PROTECTED]>
  To: 
  Sent: Thursday, July 07, 2005 1:02 AM
  Subject: Re: [Tutor] Why is this error showing up? (Original Message: 
(Tutor) What's wrong with this code?) Ignore previous post.


  > You wrote filename == raw_input("Filename to load: ") instead of
  > filename = raw_input("Filename to load: ")
  >
  > HTH,
  > Wolfram
  >
  > Nathan Pinno wrote:
  >> Hi all,
  >>
  >> Here's one of the messages that pops up:
  >>
  >> Traceback (most recent call last):
  >>   File "D:\password.py", line 77, in ?
  >> filename == raw_input("Filename to load: ")
  >> NameError: name 'filename' is not defined
  >>
  >> Why is it popping up whenever I try to load a file?
  >>
  >> Here's the latest code:
  >>
  >> # This is the code for a password protected program to store passwords.
  >> password = "hello"
  >> print "The Password Program"
  >> print "Copyright 2005 Nathan Pinno."
  >> print
  >> answer = raw_input("What is the password? ")
  >> while password != answer:
  >> print "The password is incorrect."
  >> answer = raw_input("What is the password? ")
  >> def main_menu():
  >> print "1) Add a login info card"
  >> print "2) Lookup a login info card"
  >> print "3) Remove a login info card"
  >> print "4) Print Login info list"
  >> print "5) Save login list"
  >> print "6) Open Login list"
  >> print "9) Exit"
  >>
  >> def load_login(site,filename):
  >> in_file = open(filename,"r")
  >> while 1:
  >> in_line = in_file.readline()
  >> if len(in_file) == 0:
  >> break
  >> in_line = in_line[:-1]
  >> [site,id,passcard] = string.split(in_line,",")
  >> list[site] = id and passcard
  >> in_file.close()
  >>
  >> def save_login(site,filename):
  >> out_file = open(filename,"w")
  >> for x in site.keys():
  >> out_file.write(x+","+sites[x]+"\n")
  >> out_file.close()
  >>
  >> menu_choice = "0"
  >> list = {}
  >> print "Welcome to the second half of the program."
  >> print main_menu()
  >> while menu_choice != "9":
  >> menu_choice = raw_input("Choose an option: ")
  >> if menu_choice == "1":
  >> print "Add a login info card"
  >> site = raw_input("Site: ")
  >> id = raw_input("User ID: ")
  >> passcard = raw_input("Password: ")
  >> list[site] = id and passcard
  >> menu_choice = raw_input("Choose an option: ")
  >> elif menu_choice == "2":
  >> print "Lookup a login info card"
  >> site = raw_input("Site: ")
  >> if site.has_key(site):
  >> print "The ID is: ",id(site)
  >> print "The password is: ",passcard(site)
  >> else:
  >> print site," was not found."
  >> menu_choice = raw_input("Choose an option: ")
  >> elif menu_choice == "3":
  >> print "Remove a login info card"
  >> site = raw_input("Site: ")
  >> if sites.has_key(site):
  >> del numbers[site]
  >> else:
  >> print site," was not found."
  >> menu_choice = raw_input("Choose an option: ")
  >> elif menu_choice == "4":
  >> print "Login Info"
  >> for x in site.keys():
  >> print "Site: ",x," \tID: ",numbers[x]," \tPassword: 
",numbers[x]
  >> print
  >> menu_choice = raw_input("Choose an option: ")
  >> elif menu_choice == "5":
  >> filename = raw_input("Filename to save: ")
  >> save_login(list,filename)
  >> menu_choice = raw_input("Choose an option: ")
  >> elif menu_choice == "6":
  >> filename == raw_input("Filename to load: ")
  >> load_login(list,filename)
  >> menu_choice = raw_input("Choose an option: ")
  >> print "Have a nice day!"
  >>
  >> Anything else that needs addressing?
  >>
  >> Thanks,
  >> Nathan Pinno
  >> http://www.npinnowebsite.ca/
  >>
  >
  > ___
  > 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] Why is this error showing up? (Original Message: (Tutor) What's wrong with this code?) Ignore previous post.

2005-07-07 Thread Nathan Pinno
  How do I change it to a dictionary, then? Or do I have to delete it, and 
just code it in the main part of the code?
  - Original Message - 
  From: "Ewald Ertl" <[EMAIL PROTECTED]>
  To: 
  Sent: Thursday, July 07, 2005 1:36 AM
  Subject: Re: [Tutor] Why is this error showing up? (Original Message: 
(Tutor) What's wrong with this code?) Ignore previous post.


  > Hi!
  >
  >
  > on Thu, 7 Jul 2005 01:13:48 -0600  "Nathan Pinno" 
<[EMAIL PROTECTED]> wrote :
  > 
-----
  >
  > Nathan Pinno >   Thanks Wolfram for help with that error.
  > Nathan Pinno >
  > Nathan Pinno >   Here's another that popped up:
  > Nathan Pinno >
  > Nathan Pinno >   Traceback (most recent call last):
  > Nathan Pinno >     File "D:\password.py", line 68, in ?
  > Nathan Pinno >   for x in site.keys():
  > Nathan Pinno >   AttributeError: 'str' object has no attribute 'keys'
  > Nathan Pinno >
  >
  > The Traceback tells you on which line the error is.
  > site comes from your input : site = raw_input("Site: ")
  > which is a string and not a dictionary.
  >
  >
  >
  > Nathan Pinno >   How to fix it?
  > Nathan Pinno >
  > Nathan Pinno >   Thanks,
  > Nathan Pinno >   Nathan Pinno
  > Nathan Pinno >   - Original Message - 
  > Nathan Pinno >   From: "Wolfram Kraus" <[EMAIL PROTECTED]>
  > Nathan Pinno >   To: 
  > Nathan Pinno >   Sent: Thursday, July 07, 2005 1:02 AM
  > Nathan Pinno >   Subject: Re: [Tutor] Why is this error showing up? 
(Original Message:
  > Nathan Pinno > (Tutor) What's wrong with this code?) Ignore previous 
post.
  > Nathan Pinno >
  > Nathan Pinno >
  > Nathan Pinno >   > You wrote filename == raw_input("Filename to load: ") 
instead of
  > Nathan Pinno >   > filename = raw_input("Filename to load: ")
  > Nathan Pinno >   >
  > Nathan Pinno >   > HTH,
  > Nathan Pinno >   > Wolfram
  > Nathan Pinno >   >
  > Nathan Pinno >   > Nathan Pinno wrote:
  > Nathan Pinno >   >> Hi all,
  > Nathan Pinno >   >>
  > Nathan Pinno >   >> Here's one of the messages that pops up:
  > Nathan Pinno >   >>
  > Nathan Pinno >   >> Traceback (most recent call last):
  > Nathan Pinno >   >>   File "D:\password.py", line 77, in ?
  > Nathan Pinno >   >> filename == raw_input("Filename to load: ")
  > Nathan Pinno >   >> NameError: name 'filename' is not defined
  > Nathan Pinno >   >>
  > Nathan Pinno >   >> Why is it popping up whenever I try to load a file?
  > Nathan Pinno >   >>
  > Nathan Pinno >   >> Here's the latest code:
  > Nathan Pinno >   >>
  > Nathan Pinno >   >> # This is the code for a password protected program 
to store passwords.
  > Nathan Pinno >   >> password = "hello"
  > Nathan Pinno >   >> print "The Password Program"
  > Nathan Pinno >   >> print "Copyright 2005 Nathan Pinno."
  > Nathan Pinno >   >> print
  > Nathan Pinno >   >> answer = raw_input("What is the password? ")
  > Nathan Pinno >   >> while password != answer:
  > Nathan Pinno >   >> print "The password is incorrect."
  > Nathan Pinno >   >> answer = raw_input("What is the password? ")
  > Nathan Pinno >   >> def main_menu():
  > Nathan Pinno >   >> print "1) Add a login info card"
  > Nathan Pinno >   >> print "2) Lookup a login info card"
  > Nathan Pinno >   >>     print "3) Remove a login info card"
  > Nathan Pinno >   >> print "4) Print Login info list"
  > Nathan Pinno >   >> print "5) Save login list"
  > Nathan Pinno >   >> print "6) Open Login list"
  > Nathan Pinno >   >> print "9) Exit"
  > Nathan Pinno >   >>
  > Nathan Pinno >   >> def load_login(site,filename):
  > Nathan Pinno >   >> in_file = open(filename,"r")
  > Nathan Pinno >   >> while 1:
  > Nathan Pinno >   >> in_line = in_file.readline()
  > Nathan Pinno >   >> if len(in_file) == 0:
  > Nathan Pinno >   >>     break
  > Nathan Pinno >   >>     in_line = in_line[:-1]
  > Nathan Pinno >   >> 

[Tutor] Why does invalid syntax pop up?

2005-07-07 Thread Nathan Pinno




  Hi all,
   
  Why does invalid syntax popup?
   
  Here is the latest code:
  # This is the code for a password protected program to store 
  passwords.password = "hello"print "The Password Program"print 
  "Copyright 2005 Nathan Pinno."printanswer = raw_input("What is the 
  password? ")while password != answer:    print "The 
  password is incorrect."    answer = raw_input("What is the 
  password? ")def main_menu_command():    print "1) Add a 
  login info card"    print "2) Lookup a login info 
  card"    print "3) Remove a login info 
  card"    print "4) Print Login info 
  list"    print "5) Save login list"    
  print "6) Open Login list"    print "9) Exit"
   
  def load_login_command(site,filename):    in_file = 
  open(filename,"r")    while 
  1:    in_line = 
  in_file.readline()    if 
  len(in_file) == 
  0:    
  break    in_line = 
  in_line[:-1]    [site,id,passcard] 
  = string.split(in_line,",")    
  list[site] = id and passcard    
  in_file.close()    def 
  save_login_command(site,filename):    out_file = 
  open(filename,"w")    for x in 
  site.keys():    
  out_file.write(x+","+sites[x]+"\n")    
  out_file.close()
   
  def add_login_command(site,filename):    print "Add a 
  login info card"    site = raw_input("Site: 
  ")    id = raw_input("User ID: ")    
  passcard = raw_input("Password: ")    sitelist[site] = 
  [id,passcard]
   
  def lookup_login_command(site,filename):    print 
  "Lookup a login info card"    site 
  = raw_input("Site: ")    if 
  sitelist.has_key(site):    
  print "The ID is: 
  ",sitelist[site][0]    
  print "The password is: 
  ",sitelist[site][1]    
  else:    
  print site," was not found."
   
  def remove_login_command(site,filename):    print 
  "Remove a login info card"    site 
  = raw_input("Site: ")    if 
  sites.has_key(site):    
  del sitelist[site]    
  else:    
  print site," was not found."
   
  def display_login_command(site,filename):    print 
  "Login Info"    for x in 
  site.keys():    
  print "Site: ",sitelist," \tID: ",sitelist[site]," \tPassword: 
  ",sitelist[site]    print
   
  menu_choice = "0"list = {}print "Welcome to the second half 
  of the program."main_menu()while menu_choice != 
  "9":    menu_choice = raw_input("Choose an option: 
  ")    if menu_choice == 
  "1":    
  add_login_command()    elif menu_choice == 
  "2":    
  lookup_login_command()    elif menu_choice == 
  "3":    
  remove_login_command()    elif menu_choice == 
  "4":    
  display_login_command()    elif menu_choice == 
  "5":    filename = 
  raw_input("Filename to save: ")    
  save_login_command()    elif menu_choice == 
  "6":    filename = 
  raw_input("Filename to load: ")    
  load_login_command()print "Have a nice day!"
   
  Thanks,
  Nathan Pinnohttp://www.npinnowebsite.ca/

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


Re: [Tutor] Why does invalid syntax pop up?

2005-07-07 Thread Nathan Pinno
  Here is the error:

File "D:\password.py", line 45
  site = raw_input("Site: ")
  ^
  SyntaxError: invalid syntax

  HTH,
  Nathan Pinno
  - Original Message - 
  From: "Danny Yoo" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  Cc: 
  Sent: Thursday, July 07, 2005 11:53 AM
  Subject: Re: [Tutor] Why does invalid syntax pop up?


  >
  >
  > On Thu, 7 Jul 2005, Nathan Pinno wrote:
  >
  >>   Why does invalid syntax popup?
  >
  > [text cut]
  >
  > Hi Nathan,
  >
  > What does the SyntaxError look like?  Copy-and-paste that error message
  > and bring it to the Tutor list.  One thing we want to help you do is
  > recognize what the SyntaxError is really trying to say, so that the next
  > time you see a SyntaxError, you have ways to fix it.
  >
  > Best of wishes!
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why does invalid syntax pop up?

2005-07-07 Thread Nathan Pinno
  Here is another error message:

  Traceback (most recent call last):
File "D:\password.py", line 69, in ?
  main_menu()
  NameError: name 'main_menu' is not defined

  Thanks.
  - Original Message ----- 
  From: "Nathan Pinno" <[EMAIL PROTECTED]>
  To: "Danny Yoo" <[EMAIL PROTECTED]>
  Cc: 
  Sent: Thursday, July 07, 2005 1:04 PM
  Subject: Re: [Tutor] Why does invalid syntax pop up?


  >  Here is the error:
  >
  >File "D:\password.py", line 45
  >  site = raw_input("Site: ")
  >  ^
  >  SyntaxError: invalid syntax
  >
  >  HTH,
  >  Nathan Pinno
  >  - Original Message - 
  >  From: "Danny Yoo" <[EMAIL PROTECTED]>
  >  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  >  Cc: 
  >  Sent: Thursday, July 07, 2005 11:53 AM
  >  Subject: Re: [Tutor] Why does invalid syntax pop up?
  >
  >
  >  >
  >  >
  >  > On Thu, 7 Jul 2005, Nathan Pinno wrote:
  >  >
  >  >>   Why does invalid syntax popup?
  >  >
  >  > [text cut]
  >  >
  >  > Hi Nathan,
  >  >
  >  > What does the SyntaxError look like?  Copy-and-paste that error 
message
  >  > and bring it to the Tutor list.  One thing we want to help you do is
  >  > recognize what the SyntaxError is really trying to say, so that the 
next
  >  > time you see a SyntaxError, you have ways to fix it.
  >  >
  >  > Best of wishes!
  >  >
  >  >
  > ___
  > 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] Why does invalid syntax pop up?

2005-07-07 Thread Nathan Pinno
  Here is the latest code, in case you need it:

  # This is the code for a password protected program to store passwords.
  password = "hello"
  print "The Password Program"
  print "Copyright 2005 Nathan Pinno."
  print
  answer = raw_input("What is the password? ")
  while password != answer:
  print "The password is incorrect."
  answer = raw_input("What is the password? ")
  def main_menu_command():
  print "1) Add a login info card"
  print "2) Lookup a login info card"
  print "3) Remove a login info card"
  print "4) Print Login info list"
  print "5) Save login list"
  print "6) Open Login list"
  print "9) Exit"

  def load_login_command(site,filename):
  in_file = open(filename,"r")
  while 1:
  in_line = in_file.readline()
  if len(in_file) == 0:
  break
  in_line = in_line[:-1]
  [site,id,passcard] = string.split(in_line,",")
  list[site] = id and passcard
  in_file.close()

  def save_login_command(site,filename):
  out_file = open(filename,"w")
  for x in site.keys():
  out_file.write(x+","+sites[x]+"\n")
  out_file.close()

  def add_login_command(site,filename):
  print "Add a login info card"
  site = raw_input("Site: ")
  id = raw_input("User ID: ")
  passcard = raw_input("Password: ")
  sitelist[site] = [id,passcard]

  def lookup_login_command(site,filename):
  print "Lookup a login info card"
  site = raw_input("Site: ")
  if sitelist.has_key(site):
  print "The ID is: ",sitelist[site][0]
  print "The password is: ",sitelist[site][1]
  else:
  print site," was not found."

  def remove_login_command(site,filename):
  print "Remove a login info card"
  site = raw_input("Site: ")
  if sites.has_key(site):
  del sitelist[site]
  else:
  print site," was not found."

  def display_login_command(site,filename):
  print "Login Info"
  for x in site.keys():
  print "Site: ",sitelist," \tID: ",sitelist[site]," \tPassword: 
",sitelist[site]
  print

  menu_choice = "0"
  list = {}
  print "Welcome to the second half of the program."
  main_menu()
  while menu_choice != "9":
  menu_choice = raw_input("Choose an option: ")
  if menu_choice == "1":
  add_login_command()
  elif menu_choice == "2":
  lookup_login_command()
  elif menu_choice == "3":
  remove_login_command()
  elif menu_choice == "4":
  display_login_command()
  elif menu_choice == "5":
  filename = raw_input("Filename to save: ")
  save_login_command()
  elif menu_choice == "6":
  filename = raw_input("Filename to load: ")
  load_login_command()
  print "Have a nice day!"

  HTH,
  Nathan Pinno.
  ----- Original Message - 
  From: "Nathan Pinno" <[EMAIL PROTECTED]>
  To: "Danny Yoo" <[EMAIL PROTECTED]>
  Cc: 
  Sent: Thursday, July 07, 2005 1:09 PM
  Subject: Re: [Tutor] Why does invalid syntax pop up?


  >  Here is another error message:
  >
  >  Traceback (most recent call last):
  >File "D:\password.py", line 69, in ?
  >  main_menu()
  >  NameError: name 'main_menu' is not defined
  >
  >  Thanks.
  >  - Original Message - 
  >  From: "Nathan Pinno" <[EMAIL PROTECTED]>
  >  To: "Danny Yoo" <[EMAIL PROTECTED]>
  >  Cc: 
  >  Sent: Thursday, July 07, 2005 1:04 PM
  >  Subject: Re: [Tutor] Why does invalid syntax pop up?
  >
  >
  >  >  Here is the error:
  >  >
  >  >File "D:\password.py", line 45
  >  >  site = raw_input("Site: ")
  >  >  ^
  >  >  SyntaxError: invalid syntax
  >  >
  >  >  HTH,
  >  >  Nathan Pinno
  >  >  - Original Message - 
  >  >  From: "Danny Yoo" <[EMAIL PROTECTED]>
  >  >  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  >  >  Cc: 
  >  >  Sent: Thursday, July 07, 2005 11:53 AM
  >  >  Subject: Re: [Tutor] Why does invalid syntax pop up?
  >  >
  >  >
  >  >  >
  >  >  >
  >  >  > On Thu, 7 Jul 2005, Nathan Pinno wrote:
  >  >  >
  >  >  >>   Why does invalid syntax popup?
  >  >  >
  >  >  > [text cut]
  >  >  >
  >  >  > Hi Nathan,
  >  >  >
  >  >  > What does the SyntaxError look like?  Copy-and-paste that error
  > message
  >  >  > and bring it to the Tutor list.  One thing we want to help you do 
is
  >  >  > recognize what the SyntaxError is really trying to say, so that 
the
  > next
  >  >  > time you see a SyntaxError, you have ways to fix it.
  >  >  >
  >  >  > Best of wishes!
  >  >  >
  >  >  >
  >  > ___
  >  > Tutor maillist  -  Tutor@python.org
  >  > http://mail.python.org/mailman/listinfo/tutor
  >  >
  > ___
  > 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] Why does invalid syntax pop up?

2005-07-08 Thread Nathan Pinno
  Thanks, Danny and all.

  Adjusted the code, here is the newest code and error:

  # This is the code for a password protected program to store passwords.
  password = "hello"
  print "The Password Program"
  print "Copyright 2005 Nathan Pinno."
  print
  answer = raw_input("What is the password? ")
  while password != answer:
  print "The password is incorrect."
  answer = raw_input("What is the password? ")
  def main_menu_command():
  print "1) Add a login info card"
  print "2) Lookup a login info card"
  print "3) Remove a login info card"
  print "4) Print Login info list"
  print "5) Save login list"
  print "6) Open Login list"
  print "9) Exit"

  def load_login_command(site,filename):
  in_file = open(filename,"r")
  while 1:
  in_line = in_file.readline()
  if len(in_file) == 0:
  break
  in_line = in_line[:-1]
  [site,id,passcard] = string.split(in_line,",")
  list[site] = id and passcard
  in_file.close()

  def save_login_command(site,filename):
  out_file = open(filename,"w")
  for x in site.keys():
  out_file.write(x+","+sites[x]+"\n")
  out_file.close()

  def add_login_command(site,filename):
  print "Add a login info card"
  site = raw_input("Site: ")
  id = raw_input("User ID: ")
  passcard = raw_input("Password: ")
  sitelist[site] = [id,passcard]

  def lookup_login_command(site,filename):
  print "Lookup a login info card"
  site = raw_input("Site: ")
  if sitelist.has_key(site):
  print "The ID is: ",sitelist[site][0]
  print "The password is: ",sitelist[site][1]
  else:
  print site," was not found."

  def remove_login_command(site,filename):
  print "Remove a login info card"
  site = raw_input("Site: ")
  if sites.has_key(site):
  del sitelist[site]
  else:
  print site," was not found."

  def display_login_command(site,filename):
  print "Login Info"
  for x in site.keys():
  print "Site: ",sitelist," \tID: ",sitelist[site]," \tPassword: 
",sitelist[site]
  print

  menu_choice = "0"
  list = {}
  print "Welcome to the second half of the program."
  main_menu_command()
  while menu_choice != "9":
  menu_choice = raw_input("Choose an option: ")
  if menu_choice == "1":
  add_login_command()
  elif menu_choice == "2":
  lookup_login_command()
  elif menu_choice == "3":
  remove_login_command()
  elif menu_choice == "4":
  display_login_command()
  elif menu_choice == "5":
  filename = raw_input("Filename to save: ")
  save_login_command()
  elif menu_choice == "6":
  filename = raw_input("Filename to load: ")
  load_login_command()
  print "Have a nice day!"

  Error Message:
  Traceback (most recent call last):
File "D:\password.py", line 73, in ?
  add_login_command()
  TypeError: add_login_command() takes exactly 2 arguments (0 given)

  How do I fix it so that it runs properly, and any other errors that have 
to be fixed?
  - Original Message - 
  From: "Danny Yoo" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  Cc: 
  Sent: Thursday, July 07, 2005 2:58 PM
  Subject: Re: [Tutor] Why does invalid syntax pop up?


  >
  >
  > On Thu, 7 Jul 2005, Nathan Pinno wrote:
  >
  >>   Here is another error message:
  >>
  >>   Traceback (most recent call last):
  >> File "D:\password.py", line 69, in ?
  >>   main_menu()
  >>   NameError: name 'main_menu' is not defined
  >
  >
  > Hi Nathan,
  >
  > The error message is correct: there is no "main_menu()" function.  There
  > is, however, a "main_menu_command()" function that's defined right at 
the
  > top.  Did you mean that instead?
  >
  > And just out of curiosity, when did you get this NameError message?
  > Before the SyntaxError, or after?  The reason I ask is because if you're
  > still hitting SyntaxError, there should no be possible way for the 
program
  > to even get to NameError --- a SyntaxError is a show-stopper.
  >
  > Is the SyntaxError still showing up?  As far as I could tell, your code
  > looked fine from a syntactic point of view.
  >
  >
  >
  > Best of wishes to you!
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why does invalid syntax pop up? (fwd)

2005-07-09 Thread Nathan Pinno
Hey all, 

Just a notice, I'm quitting work on this program, too complicated for me to
work out, I'm getting lost now and can't figure out the bugs anymore. I
think for know I'll work on my Giant Calculator application, which I'll show
the code when it's done. If anyone is interested in finishing it, just give
me a shout, and I'll send it to you as a ZIP file.

Thanks,
Nathan Pinno
Crew, McDonalds Restaurant, Camrose, AB, Canada
http://www.npinnowebsite.ca


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Brian van den Broek
Sent: July 8, 2005 5:16 PM
Cc: Tutor
Subject: Re: [Tutor] Why does invalid syntax pop up? (fwd)

Danny Yoo said unto the world upon 08/07/2005 18:14:
> [Nathan, please don't send only to me: make sure you're using "Reply 
> to All" and that tutor@python.org is also being replied to.  I'm 
> actually going slightly crazy with work right now, but there are other 
> people on the mailing list who can help.
> 
> I'm forwarding your message to the rest of the mailing list now.  Good 
> luck!]
> 
> 
> -- Forwarded message --
> Date: Fri, 8 Jul 2005 16:08:53 -0600
> From: Nathan Pinno <[EMAIL PROTECTED]>
> To: Danny Yoo <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Why does invalid syntax pop up?
> 
>   Here's another:
> 
>   Traceback (most recent call last):
> File "D:\password.py", line 73, in ?
>   add_login_command()
>     File "D:\password.py", line 41, in add_login_command
>   sitelist[site] = [id,passcard]
>   NameError: global name 'sitelist' is not defined


Nathan,

if you take a look at my examples with the function I called
name_dropper() that might help you understand this. The problem here is that
you have only ever assigned anything to sitelist within the body of your
various functions. So, the name doesn't 'have meaning' at the global level.

I see from the code I sniped that you dealt with the last problem by
removing the spurious arguments from the function definition. But I also
notice you left them in in other functions with exactly the same problem.

I suggest you go through your functions and verify, for each of your
arguments, that you are actually using them. Once done that, go through and
check that any assignments made within functions are propagated out of them
if they are needed in body code. (That was the point of the top_level_name =
name_keeper() example I gave.

Best,

Brian vdB

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


[Tutor] Is it possible to...

2005-07-09 Thread Nathan Pinno



Hi all,
 
I was just wondering if it is possible to use Python as a language to 
password protect a webpage? If it is possible, I wouldn't mind learning how, it 
would enable me to add a member-only section to my website.
 
Thanks,
Nathan PinnoCrew, McDonalds Restaurant, Camrose, AB Canadahttp://www.npinnowebsite.ca/

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


[Tutor] What's the invalid syntax?

2005-07-09 Thread Nathan Pinno



What's the invalid syntax?
 
Here's the code (Part of my Guess the Numbers game):
 
    if a0 == x0 and a1 == x1 and a2 
== x2 and a3 == 
x3:    print 
"Congratulations! Way to 
go?"    
answer = raw input("Play again: (Y)es or (N)o Type the letter of your choice. 
")
 
Thanks,
Nathan PinnoCrew, McDonalds Restaurant, Camrose, AB Canadahttp://www.npinnowebsite.ca/

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


Re: [Tutor] Is it possible to...

2005-07-09 Thread Nathan Pinno
  Could you send me the code if possible, or show me the way to go?
  - Original Message - 
  From: "nephish" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  Sent: Saturday, July 09, 2005 12:32 PM
  Subject: Re: [Tutor] Is it possible to...


  >i am, with a simple if-then statement. works ok, not the most secure
  > (like what you would expect with something like pay-pal) but works for
  > what i need.
  > i have a dictionary that references the username to a password.
  > if the username is not in the list, they get kicked to a different page.
  >
  >
  > On Sat, 2005-07-09 at 13:07 -0600, Nathan Pinno wrote:
  >> Hi all,
  >>
  >> I was just wondering if it is possible to use Python as a language to
  >> password protect a webpage? If it is possible, I wouldn't mind
  >> learning how, it would enable me to add a member-only section to my
  >> website.
  >>
  >> Thanks,
  >> Nathan Pinno
  >> Crew, McDonalds Restaurant, Camrose, AB Canada
  >> http://www.npinnowebsite.ca/
  >> ___
  >> Tutor maillist  -  Tutor@python.org
  >> http://mail.python.org/mailman/listinfo/tutor
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Can I use def without ( ) at the end?

2005-07-09 Thread Nathan Pinno



Hi all,
 
Is the subject possible without getting an error?
 
Nathan PinnoCrew, McDonalds Restaurant, Camrose, AB Canadahttp://www.npinnowebsite.ca/

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


Re: [Tutor] Can I use def without ( ) at the end?

2005-07-09 Thread Nathan Pinno
  Hi all,

  How do I make Python get a def? Is it the "get" function, or something
  else? I need to know so that I can get a def for that computer
  MasterMind(tm) game that I'm writing.

  BTW, I took your advice, and wrote some definitions for my Giant
  Calculator program. Might make the code easier to read, but harder to code
  because I have to keep going to the top to read the menu. Not that fun, 
but
  necessary for a smooth program, I guess.

  Nathan Pinno

  - Original Message - 
  From: "Brian van den Broek" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  Cc: 
  Sent: Saturday, July 09, 2005 6:15 PM
  Subject: Re: [Tutor] Can I use def without ( ) at the end?


  > Nathan Pinno said unto the world upon 09/07/2005 19:03:
  >> Hi all,
  >>
  >> Is the subject possible without getting an error?
  >>
  >> Nathan Pinno
  >> Crew, McDonalds Restaurant, Camrose, AB Canada
  >> http://www.npinnowebsite.ca/
  >
  > No. Why do you want to do this? If it is to have a function with no
  > arguments:
  >
  > >>> def no_args():
  > ... print "I've no arguments"
  > ...
  > >>> no_args()
  > I've no arguments
  > >>>
  >
  > Brian vdB
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can I use def without ( ) at the end?

2005-07-09 Thread Nathan Pinno
  Also, I just wanted to know because I'm using it in my Giant Computer 
program for the menus, so I don't have to keep re-typing them.

  Nathan Pinno
  - Original Message - 
  From: "Brian van den Broek" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  Cc: 
  Sent: Saturday, July 09, 2005 6:15 PM
  Subject: Re: [Tutor] Can I use def without ( ) at the end?


  > Nathan Pinno said unto the world upon 09/07/2005 19:03:
  >> Hi all,
  >>
  >> Is the subject possible without getting an error?
  >>
  >> Nathan Pinno
  >> Crew, McDonalds Restaurant, Camrose, AB Canada
  >> http://www.npinnowebsite.ca/
  >
  > No. Why do you want to do this? If it is to have a function with no
  > arguments:
  >
  > >>> def no_args():
  > ... print "I've no arguments"
  > ...
  > >>> no_args()
  > I've no arguments
  > >>>
  >
  > Brian vdB
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can I use def without ( ) at the end?

2005-07-09 Thread Nathan Pinno
  Brian,

  I'll do one better and post the code after I'm done writing it. Then you 
can decide for yourself what I'm trying to do.

  Nathan P.
  - Original Message - 
  From: "Brian van den Broek" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  Cc: 
  Sent: Saturday, July 09, 2005 6:54 PM
  Subject: Re: [Tutor] Can I use def without ( ) at the end?


  > Nathan Pinno said unto the world upon 09/07/2005 20:36:
  >
  > 
  >
  >>  - Original Message -  From: "Brian van den Broek"
  >>
  >>  > Nathan Pinno said unto the world upon 09/07/2005 19:03:
  >>  >> Hi all,
  >>  >>
  >>  >> Is the subject possible without getting an error?
  >>  >>
  >>  >> Nathan Pinno
  >>  >> Crew, McDonalds Restaurant, Camrose, AB Canada
  >>  >> http://www.npinnowebsite.ca/
  >>  >
  >>  > No. Why do you want to do this? If it is to have a function with no
  >>  > arguments:
  >>  >
  >>  > >>> def no_args():
  >>  > ... print "I've no arguments"
  >>  > ...
  >>  > >>> no_args()
  >>  > I've no arguments
  >>  > >>>
  >>  >
  >>  > Brian vdB
  >>
  >>
  >>
  >>   Also, I just wanted to know because I'm using it in my Giant Computer
  >>  program for the menus, so I don't have to keep re-typing them.
  >>
  >>   Nathan Pinno
  >
  >
  > Nathan,
  >
  > I'm afraid I don't know what you meant in your other post by "get a
  > def". I'm also unclear on what it is you feel that you are having to
  > retype.
  >
  > The usual way to have some functions and 'drive' them through a text
  > menu is either a dictionary dispatch (don't worry about that right
  > now) or something simpler like:
  >
  >
  > >>> def function_1():
  > ... print "I am function 1!"
  > ...
  > >>> def function_2():
  > ... print "I am function 2!"
  > ...
  > >>> def menu():
  > ... print "I'm a simple menu system."
  > ... print "Enter 1 for function 1"
  > ... print "Enter 2 for function 2"
  > ... choice = raw_input("Your selection please?\n")
  > ... if choice == '1':
  > ... function_1()
  > ... elif choice == '2':
  > ... function_2()
  > ... else:
  > ... print "Please read more carefully"
  >
  > Try that at the prompt, and then call the menu function -- on a line,
  > type:
  >
  > menu()
  >
  > If that isn't helping, you are going to have to explain more clearly
  > what problem it is that you are trying to avoid.
  >
  > Brian vdB
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What's going on with this code? Error message supplied.

2005-07-09 Thread Nathan Pinno



Here is the error message:
 
Traceback (most recent call last):  File "D:\GC.py", line 67, in 
?    if option == 1:NameError: name 'option' is not 
defined
And the relevant code:
 
print "The Giant Calculator"printprint "Copyright 2005 Written and 
debugged by Nathan Pinno"print print main_menu()if option == 
1:
 
and the dictionary code:
 
def main_menu():   print "OPTIONS MENU"   print 
"1) Calculate"   print "2) Shapes"   print "3) 
Temperature"   print "4) Formulas"   print "5) 
Quit"   option = input("What option would you like:" ) 
 
Thanks ahead of time,
Nathan Pinnohttp://www.npinnowebsite.ca/

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


[Tutor] Looks like Giant Calc is a bust.

2005-07-09 Thread Nathan Pinno



Hey all,
 
The Giant Calculator runs now, just not as I want it to. I can't seem to 
get it past the main menu. Here is the code:
 
# This program is designed as a big calculator with functions.
 
# This first bunch of code is for the various menus. I decided to divide 
the calculations into seperate sub-menus,#so that the main menus would not 
be that long.option = 0a = 0b = 0temp_option = 
0formula_option = 0
 
def main_menu():   print "OPTIONS MENU"   print 
"1) Calculate"   print "2) Shapes"   print "3) 
Temperature"   print "4) Formulas"   print "5) 
Quit"   option = input("What option would you like:" ) 
 
def cal_menu():    print "CALCULATE 
MENU"    print "1) Add"    print "2) 
Subraction"    print "3) 
Multiplication"    print "4) Division w/o 
remainder"    print "5) Division with 
remaider"    print "6) Exponation"    
print "7) Square roots"    print "8) Back to the previous 
menu."    a = input("What option would you like:" )
 
def shape_menu():    print "SHAPES 
MENU"    print "Important: The figure that is used for pi is 
3.14."    print "1) Squares"    print "2) 
Circles"    print "3) Rectangles"    print 
"4) Triangles"    print "5) Cones"    
print "6) Cylinders"    print "7) 
Semicircles"    print "8) Main menu"    b 
= input("What option would you like?" )
 
def temp_menu():    print "1) Convert degrees Kevins to 
degrees Celsius"    print "2) Contvert Fahrenheit to 
Celsius"    print "3) Convert Celsius to 
Fahrenheit"    print "4) Convert Celsius to 
Kelvins"    print "5) Convert Kelvins to 
Fahrenheit"    print "6) Convert Fahrenheit to 
Kelvins"    print "7) Main Menu"    
temp_option = input("Choice: ")
 
def formula_menu():    print "1) 
Interest"    print "2) Distance"    print 
"3) Uniform motion"    print "4) 
Momentum"    print "5) Uniformly accelerated 
motion"    print "6) Falling bodies"    
print "7) Weight"    print "8) Main 
menu"    fourmula_option = input("Choice: ")
 
#Code for main part of program.print "The Giant 
Calculator"printprint "Copyright 2005 Written and debugged by Nathan 
Pinno"print print main_menu()if option == 1:    
print cal_menu()    if a == 
1:    X = input("First number:" 
)    Y = input("Second number:" 
)    print X, "+", Y, "= ",X + 
Y    print 
cal_menu()    elif a == 
2:    X = input("First number:" 
)    Y = input("Second number:" 
)    print X, "-", Y, "= ",X - 
Y    print 
cal_menu()    elif a == 
3:    X = input("First number:" 
)    Y = input("Second number:" 
)    print X, "*", Y, "= ",X * 
Y    print 
cal_menu()    elif a == 
4:    X = input("First number:" 
)    Y = input("Second number:" 
)    if Y == 
0:    print 
"Division by zero ot 
allowed!"    
Y = input("Second number:" )    
else:    
print X, "/", Y, "= ",X / 
Y    print 
cal_menu()    elif a == 
5:    X = input("First number:" 
)    Y = input("Second number:" 
)    if Y == 
0:    print 
"Division by zero ot 
allowed!"    
Y = input("Second number:" )    
else:    
print X, "/", Y, "= ",X / Y," R ", X % 
Y    print 
cal_menu()    elif a == 
6:    X = input("First number:" 
)    Y = input("Power:" 
)    print X, "**", Y, "= 
",X**Y    print 
cal_menu()    elif a == 
7:    X = input("Number to be 
squared:" )    print "The square root 
of", X, " = ",X**0.5    print 
cal_menu()    elif a == 
8:    print 
main_menu()    
else:    print "That's not an option. 
Try again."    a = input("What option 
would you like:" )elif option == 2:    print 
shape_menu()    if b == 
1:    print "1) 
Circumference"    print "2) 
Area"    print "3) Shapes 
Menu"    op = input("Choice: 
")    if op == 
1:    side = 
input("Side: 
")    print 
"Circumference = 
",4*side    
print shape_menu()    elif op == 
2:    side = 
input("Side: 
")    print 
"Area = 
",side**2    
print shape_menu()    elif op == 
3:    print 
shape_menu()    
else: 

Re: [Tutor] What's the invalid syntax? [What's the error mesaage?]

2005-07-10 Thread Nathan Pinno
  I fixed this bug by myself, I had forgotten to add a print on a line by 
itself.
  - Original Message - 
  From: "Danny Yoo" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  Cc: 
  Sent: Sunday, July 10, 2005 12:29 AM
  Subject: Re: [Tutor] What's the invalid syntax? [What's the error 
mesaage?]


  >
  >
  > On Sat, 9 Jul 2005, Nathan Pinno wrote:
  >
  >> What's the invalid syntax?
  >>
  >> Here's the code (Part of my Guess the Numbers game):
  >>
  >> if a0 == x0 and a1 == x1 and a2 == x2 and a3 == x3:
  >> print "Congratulations! Way to go?"
  >> answer = raw input("Play again: (Y)es or (N)o Type the 
letter of your choice. ")
  >
  >
  > Hi Nathan,
  >
  > Next time you ask this kind of question, show us the error message.
  > Brian has asked you before on other questions in the past; his
  > recommendation is a good one in general.
  >
  > Error message are not content-less, despite what you might think.  They
  > usually have some kind of useful information associated with them, and
  > they they really often provide key clues to what's broken.
  >
  >
  > Let's try an example to demonstrate this idea.  Let's say that we write 
a
  > program like this:
  >
  > ##
  > def test_syntax_error():
  >print "hello world"
  >goodbye world
  > ##
  >
  > When we run this, Python says that there's a problem here.  But it
  > actually says more than "it doesn't work"; it gets specific:
  >
  > ##
  >  File "", line 3
  >goodbye world
  >^
  > SyntaxError: invalid syntax
  > ##
  >
  > Python is saying: "Up to line 2 of the program, things look 
syntactically
  > ok.  I, the Python system, hit a problem on line three.  Here, I'll show
  > the line to you; maybe you'll see what's wrong immediately.  Look around
  > there for the syntax error.  If it helps here's more info: I got 
confused
  > as soon as I saw the word 'world'; I was not expecting that word there."
  >
  > Of course, if Python really did say something like that in full English,
  > it would be too verbose.  So it does take some practice in reading
  > something terse like an error message, and actually understanding what 
it
  > means.  But many of us on the tutor list have that experience.
  >
  > I hope this makes it clear: if you see an error message, include it!
  > It's actually really useful for us when we try to help you with 
problems.
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Another newbie question from Nathan.

2005-07-10 Thread Nathan Pinno
  Hi all,

  How do I make Python get a def? Is it the "get" function, or something

else? I need to know so that I can get a def for that computer 
MasterMind(tm) game that I'm writing.

  BTW, I took your advice, and wrote some definitions for my Giant 
Calculator program. Might make the code easier to read, but harder to
code 
because I have to keep going to the top to read the menu. Not that fun,
but 
necessary for a smooth program, I guess.

  Nathan Pinno

  "Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
  > On Sat, 02 Jul 2005 00:25:00 -0600, Nathan Pinno wrote:
  >>   Hi all.
  >>   How do I make the computer generate 4 random numbers for the
guess? I 
want
  >> to know because I'm writing a computer program in Python like the
game
  >> MasterMind.
  > First you get the computer to generate one random number. Then you
do it
  > again three more times.
  > If you only need to do it once, you could do it this way:
  > import random  # you need this at the top of your program
  > x0 = random.random()
  > x1 = random.random()
  > x2 = random.random()
  > x3 = random.random()
  > But if you need to do it more than once, best to create a function
that
  > returns four random numbers in one go.
  > def four_random():
  >"""Returns a list of four random numbers."""
  >L = []  # start with an empty list
  >for i in range(4):
  >L.append(random.random())
  >return L
  > and use it this way:
  > rand_nums = four_random()
  > # rand_nums is a list of four numbers
  > print rand_nums[0]  # prints the first random number
  > print rand_nums[3]  # prints the last one
  > or like this:
  > alpha, beta, gamma, delta = four_random()
  > # four names for four separate numbers
  > Steven.
  > http://mail.python.org/mailman/listinfo/python-list


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


Re: [Tutor] What's going on with this code? Error message supplied.

2005-07-10 Thread Nathan Pinno
  Here's an error message:

File "D:\GC.py", line 78
  cal_opt = cal_menu()
  ^
  SyntaxError: invalid syntax

  The relevant code:

  option = main_menu()
  if option == 1:
  cal_menu()
  cal_opt = cal_menu()
  if cal_opt == 1:

  How do I fix this error?

  Nathan
  - Original Message - 
  From: "Alan G" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>; 
  Sent: Sunday, July 10, 2005 2:16 AM
  Subject: Re: [Tutor] What's going on with this code? Error message 
supplied.


  > Nathan,
  >
  >> Subject: [Tutor] What's going on with this code? Error message
  >> supplied.
  >>
  >
  >> Here is the error message:
  >>
  >> Traceback (most recent call last):
  >>  File "D:\GC.py", line 67, in ?
  >>if option == 1:
  >> NameError: name 'option' is not defined
  >
  > The error message tells you what is wrong, option is not defined at
  > the
  > point where you are using it. Pythopn starts executing code from the
  > top
  > so when it comes to your line
  >
  > if option == 1
  >
  > it doesn't know about anything called option, you haven't created it
  > yet.
  > In fact you only ever create it inside the main_menu() function. But
  > names
  > created inside functions are only seen inside the function  - they are
  > called "local" because they are localised to the function. You need
  > to create a variable outside the function, then return the value from
  > the function to that variabl;e like this:
  >
  > option = main_menu()   # assign the value thus creating option
  > if option == 1:# now you can test it
  >
  >
  > But your program has another problem.
  >
  >> print main_menu()
  >
  > main_menu is a function which prints a menu. You do not need to
  > use print here. There are print commands inside the function.
  > In fact what this says is print the return value of main_menu()
  > and, as it stands, you don't have a return value so Python will
  > print 'None', which you don't want.
  >
  >> def main_menu():
  >>print "OPTIONS MENU"
  >>print "1) Calculate"
  >> ...
  >>print "5) Quit"
  >>option = input("What option would you like:" )
  > return option
  >
  > And finally to get my code above to work you need to return
  > the option value as shown above.
  >
  > You might want to rethink using input() too sibnce it has some
  > security issues,
  >
  > option = int(raw_input())
  >
  > is safer and for youur purposes does the same thing.
  >
  > Take some time to work through a tutorial, that should explain these
  > issues. In the long run it will be faster than writing code and
  > posting every problem here, then waiting for an answer!
  >
  > Alan G
  > Author of the Learn to Program web tutor
  > http://www.freenetpages.co.uk/hp/alan.gauld
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Why does my code show this?

2005-07-10 Thread Nathan Pinno




  Hey all,
   
  Thought I'd try a mini-calc. Here's the code:
   
  # This is a small calculator.print "Mini Calculator"print "By 
  Nathan Pinno"printprint "CALCULATE MENU"print "1) Add"print 
  "2) Subraction"print "3) Multiplication"print "4) Division w/o 
  remainder"print "5) Division with remaider"print "6) 
  Exponation"print "7) Square roots"print "8) Exit"cal_opt = 
  int(raw_input("What option would you like: "))if cal_opt == 
  "1":    X = input("First number:" )    Y 
  = input("Second number:" )    print X, "+", Y, "= ",X + 
  Y    cal_opt = int(raw_input("Option: "))elif cal_opt 
  == "2":    X = input("First number:" 
  )    Y = input("Second number:" )    
  print X, "-", Y, "= ",X - Y    cal_opt = 
  int(raw_input("Option: "))elif cal_opt == "3":    X = 
  input("First number:" )    Y = input("Second number:" 
  )    print X, "*", Y, "= ",X * Y    
  cal_opt = int(raw_input("Option: "))elif cal_opt == 
  "4":    X = input("First number:" )    Y 
  = input("Second number:" )    if Y == 
  0:    print "Division by zero ot 
  allowed!"    Y = input("Second 
  number:" )    
  else:    print X, "/", Y, "= ",X / 
  Y    cal_opt = 
  int(raw_input("Option: "))elif cal_opt == "5":    X = 
  input("First number:" )    Y = input("Second number:" 
  )    if Y == 
  0:    print "Division by zero ot 
  allowed!"    Y = input("Second 
  number:" )    
  else:    print X, "/", Y, "= ",X / 
  Y," R ", X % Y    cal_opt = 
  int(raw_input("Option: "))elif cal_opt == "6":    X = 
  input("First number:" )    Y = input("Power:" 
  )    print X, "**", Y, "= ",X**Y    
  cal_opt = int(raw_input("Option: "))elif cal_opt == 
  "7":    X = input("Number to find the square root of:" 
  )    print "The square root of", X, " = 
  ",X**0.5    cal_opt = int(raw_input("Option: "))elif 
  cal_opt == "8":    print 
  "Goodbye!"else:    print "That's not an option. Try 
  again."    cal_opt = int(raw_input("Option: "))
  Here is the screen output:
   
  Mini CalculatorBy Nathan Pinno
   
  CALCULATE MENU1) Add2) Subraction3) Multiplication4) 
  Division w/o remainder5) Division with remaider6) Exponation7) 
  Square roots8) ExitWhat option would you like: 7That's not an 
  option. Try again.Option: 33*412>>> 
   
  Why does it run this way instead of going to the proper equation?
   
  Appreciating the help so far,
  Nathan Pinno

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


Re: [Tutor] Why does my code show this?

2005-07-10 Thread Nathan Pinno
  Thanks to all in the group. Mini_calc is now up and running successfully 
and is now available to download from my site.

  Thanks again,
  Nathan
  - Original Message - 
  From: "Alan G" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>; 
  Sent: Sunday, July 10, 2005 5:03 PM
  Subject: Re: [Tutor] Why does my code show this?


  >>  cal_opt = int(raw_input("What option would you like: "))
  >
  > Here you get the input and convert it to a number (int() )
  > which is fine.
  >
  >>  if cal_opt == "1":
  >
  > But here you compare it to a string (see the quotes).
  >
  > So either remove the convertion to int() around raw_input or
  > remove the quotes around the values. The things you compare
  > must be the same type.
  >
  >>  That's not an option. Try again.
  >>  Option: 3
  >>  3*4
  >>  12
  >
  > I'm not sure how the multiplication appeared though!
  >
  > Alan G.
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Giant Calc runs, but need advice on how to make the menu repopup.

2005-07-12 Thread Nathan Pinno



It runs but now how do I make it go back to the previous menu (e.g. from 
Add to Calculate Menu?)
 
Here is the latest screenshot:
 
The Giant Calculator
 
Copyright 2005 Written and debugged by Nathan Pinno
 
OPTIONS MENU1) Calculate2) Shapes3) Temperature4) 
Formulas5) QuitWhat option would you like:1CALCULATE MENU1) 
Add2) Subraction3) Multiplication4) Division w/o remainder5) 
Division with remaider6) Exponation7) Square roots8) Back to the 
previous menu.What option would you like:3First number:3Second 
number:23 * 2 =  6CALCULATE MENU1) Add2) Subraction3) 
Multiplication4) Division w/o remainder5) Division with remaider6) 
Exponation7) Square roots8) Back to the previous menu.What option 
would you like:7
 
>>> 
 
and the current code:
 
# This program is designed as a big calculator with functions.
 
# This first bunch of code is for the various menus. I decided to divide 
the calculations into seperate sub-menus,#so that the main menus would not 
be that long.def main_menu():   global option   
print "OPTIONS MENU"   print "1) Calculate"   print 
"2) Shapes"   print "3) Temperature"   print "4) 
Formulas"   print "5) Quit"   option = input("What 
option would you like:" ) 
 
def cal_menu():    global cal_opt    
print "CALCULATE MENU"    print "1) 
Add"    print "2) Subraction"    print "3) 
Multiplication"    print "4) Division w/o 
remainder"    print "5) Division with 
remaider"    print "6) Exponation"    
print "7) Square roots"    print "8) Back to the previous 
menu."    cal_opt = input("What option would you like:" 
)
 
def shape_menu():    global 
shape_opt    print "SHAPES MENU"    print 
"Important: The figure that is used for pi is 3.14."    print 
"1) Squares"    print "2) Circles"    
print "3) Rectangles"    print "4) 
Triangles"    print "5) Cones"    print 
"6) Cylinders"    print "7) 
Semicircles"    print "8) Main menu"    
shape_opt = input("What option would you like?" )
 
def temp_menu():    global 
temp_opt    print "1) Convert degrees Kevins to degrees 
Celsius"    print "2) Contvert Fahrenheit to 
Celsius"    print "3) Convert Celsius to 
Fahrenheit"    print "4) Convert Celsius to 
Kelvins"    print "5) Convert Kelvins to 
Fahrenheit"    print "6) Convert Fahrenheit to 
Kelvins"    print "7) Main Menu"    
temp_option = input("Choice: ")
 
def formula_menu():    global 
formula_opt    print "1) Interest"    
print "2) Distance"    print "3) Uniform 
motion"    print "4) Momentum"    print 
"5) Uniformly accelerated motion"    print "6) Falling 
bodies"    print "7) Weight"    print "8) 
Main menu"    fourmula_option = input("Choice: ")
 
#Code for main part of program.print "The Giant 
Calculator"printprint "Copyright 2005 Written and debugged by Nathan 
Pinno"print main_menu()if option == 1:    
cal_menu()    if cal_opt == 
1:    X = input("First number:" 
)    Y = input("Second number:" 
)    print X, "+", Y, "= ",X + 
Y    cal_menu()    
elif cal_opt == 2:    X = 
input("First number:" )    Y = 
input("Second number:" )    print X, 
"-", Y, "= ",X - Y    
cal_menu()    elif cal_opt == 
3:    X = input("First number:" 
)    Y = input("Second number:" 
)    print X, "*", Y, "= ",X * 
Y    cal_menu()    
elif cal_opt == 4:    X = 
input("First number:" )    Y = 
input("Second number:" )    if Y == 
0:    print 
"Division by zero ot 
allowed!"    
Y = input("Second number:" )    
else:    
print X, "/", Y, "= ",X / 
Y    
cal_menu()    elif cal_opt == 
5:    X = input("First number:" 
)    Y = input("Second number:" 
)    if Y == 
0:    print 
"Division by zero ot 
allowed!"    
Y = input("Second number:" )    
else:    
print X, "/", Y, "= ",X / Y," R ", X % 
Y    
cal_menu()    elif cal_opt == 
6:    X = input("First number:" 
)    Y = input("Power:" 
)    print X, "**", Y, "= 
",X**Y    
cal_menu()    elif cal_opt == 
7:    X = input("Number to be 
squared:" )    print "The square root 
of", X, " = ",X**0.5    
cal_menu()    elif cal_opt == 
8:    
main_menu()    
else:    print "That

[Tutor] Just finished creating Shape_Calc.

2005-07-17 Thread Nathan Pinno



Hey all,
 
Just finished shape_calc.py. If anyone is interested in going through the 
code, before I send it to my website, let me know. If no one answers this within 
a week, I post the zip file on my site.
 
Nathan Pinno.

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


Re: [Tutor] Just finished creating Shape_Calc.

2005-07-17 Thread Nathan Pinno




  Luke and all,
   
  Shape_calc helps you to find the area, perimeter, and other 
  info about shapes.
   
  Simple enough.
  
- Original Message - 
From: 
luke 
To: Nathan Pinno 
Sent: Sunday, July 17, 2005 9:42 
PM
Subject: Re: [Tutor] Just finished 
creating Shape_Calc.

what does shape_calc do?
-Luke

  - Original Message - 
  From: 
  Nathan Pinno 
  To: tutor@python.org 
  Sent: Sunday, July 17, 2005 9:57 
  PM
  Subject: [Tutor] Just finished 
  creating Shape_Calc.
  
  Hey all,
   
  Just finished shape_calc.py. If anyone is interested in going through 
  the code, before I send it to my website, let me know. If no one answers 
  this within a week, I post the zip file on my site.
   
  Nathan Pinno.
  
  
  

  ___Tutor 
  maillist  -  Tutor@python.orghttp://mail.pythonorg/mailman/listinfo/tutor

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


[Tutor] I am going to change Giant Calculator into mini calculators.

2005-07-17 Thread Nathan Pinno



Hey all,
 
The subject says it all. If anyone is interested in working on Giant 
Calculator, give me a shout, and I'll send you a ZIP file with the PY 
file.
 
Nathan

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


Re: [Tutor] Who uses input()? [was Re: question on "input"]

2005-07-18 Thread Nathan Pinno
  Terry and all,

  I thought something like this might popup.

  I find it easier to remember and faster to code than int(raw_input()). The 
faster I can code a program, the better in my opinion. So what if it has a 
few bugs, I fix them gradually.

  Nathan Pinno
  - Original Message - 
  From: "Terry Reedy" <[EMAIL PROTECTED]>
  To: 
  Sent: Monday, July 18, 2005 1:04 AM
  Subject: Re: Who uses input()? [was Re: question on "input"]


  >
  > "Nathan Pinno" <[EMAIL PROTECTED]> wrote in message
  > news:[EMAIL PROTECTED]
  >>  I use input() all the time. I know many people say it ain't safe, but
  >> whose going to use it to crash their own comp? Only an insane person
  >> would,
  >
  > This is usage Guido intended it for, not for production apps distributed 
to
  > world.
  >
  >
  >
  > -- 
  > http://mail.python.org/mailman/listinfo/python-list
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Who uses input()? [was Re: question on "input"]

2005-07-18 Thread Nathan Pinno
  Danny,

  It sure did, though I wish there was an easier way of coding it than 
int(raw_input())! Any ideas would gladly be appreciated.

  By the way, is there any code floating out there that can show how many 
possible mixtures there are, e.g. for x0, x1, x2, x3, and a0, a1, a2, and a3 
for example. If there is, show me it, please. I'm getting confused writing 
my MasterMind and don't want to screw up bad, e.g. repeat the same answer in 
a different way.

  Thanks,
  Nathan Pinno.
  - Original Message - 
  From: "Danny Yoo" <[EMAIL PROTECTED]>
  To: "Nathan Pinno" <[EMAIL PROTECTED]>
  Cc: "Terry Reedy" <[EMAIL PROTECTED]>; 
  Sent: Monday, July 18, 2005 2:14 AM
  Subject: Re: [Tutor] Who uses input()? [was Re: question on "input"]


  >
  >
  > On Mon, 18 Jul 2005, Nathan Pinno wrote:
  >
  >> I find it easier to remember and faster to code than int(raw_input()).
  >> The faster I can code a program, the better in my opinion. So what if 
it
  >> has a few bugs, I fix them gradually.
  >
  > Hi Nathan
  >
  > You're right, just as long as we're writing programs that are only meant
  > to be used by ourselves, and as long as we're sure that it's not talking
  > to the outside world.  The driving issue behind getting paranoid is 
this:
  > it's getting much easier to write programs that we think might be just 
for
  > ourselves, but which become useful for others.
  >
  > And as soon as we write programs that other people are going to use, we
  > really do have to play by a different set of rules than just ease of
  > programming.  Some folks were casual about eval(), and look what 
happened
  > to them:
  >
  >http://gulftech.org/?node=research&article_id=00088-07022005
  >
  > They should have known better.
  >
  > This problem is not exclusive to programmers in PHP:  programmers in
  > Python make the same kind of mistakes.  As a concrete example, take a 
look
  > at the comments about the deprecated "SimpleCookie" and "SerialCookie"
  > functions:
  >
  >http://www.python.org/doc/lib/module-Cookie.html
  >
  > Again, they should have known better.  And we should know better.
  >
  > So we do have a responsibility to state up front that using 'eval' (or
  > things that call 'eval' for us) is convenient, but it's not safe. 
That's
  > why we bug about it every so often.
  >
  >
  > Hope this helps!
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shape_calc.py

2005-07-18 Thread Nathan Pinno




  Raj,
   
  Shape_calc is a calculator for finding information about shapes, e.g. 
  perimeter, area, and so forth.
   
  HTH (Hope This Helps),
  Nathan Pinno
  
- Original Message - 
From: 
Raj 
Moodley 
To: [EMAIL PROTECTED] 
Sent: Monday, July 18, 2005 2:54 
AM
Subject: shape_calc.py


Hi Nathan, wanted 
to find out what is shape_calc.py 
about? Am a newbie.
 
Kind 
regards
 
Raj 
Moodley
 

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


Re: [Tutor] shape_calc.py

2005-07-18 Thread Nathan Pinno




  Raj,
   
  My original interest was for school, now I use it to develop games and 
  apps. I work at McDonalds Restaurant as Crew. I have developed another app 
  called mini_calc and a game called Guess the Number; and was working on Giant 
  Calculator, but gave up on it. I am also working on a MasterMind-like game, 
  but it giving me headaches :).
   
  Nathan Pinno.
  P.S. Enjoy the shape_calc. You can find Mini_calc and Guess the Number on 
  my site at this address: http://www.npinnowebsite.ca/download.htm. 
  
  
- Original Message - 
From: 
Raj 
Moodley 
To: 'Nathan Pinno' 
Sent: Monday, July 18, 2005 9:56 
AM
Subject: RE: shape_calc.py

    
    Hi Nathan, thanks 
for the email, please send it to me, would like to improve my 
understanding.
 
What do u do? 
What’s your interest in Python? Have you developed any other apps using 
Python?
 

Kind 
regards
 
Raj 
Moodley 

 




From: 
Nathan Pinno [mailto:[EMAIL PROTECTED]] Sent: 18 July 2005 03:41 PMTo: Raj MoodleyCc: tutor@python.orgSubject: Re: 
shape_calc.py
 

  
  Raj,
  
   
  
  Shape_calc is a calculator for 
  finding information about shapes, e.g. perimeter, area, and so 
  forth.
  
   
  
  HTH (Hope This 
  Helps),
      
  Nathan 
  Pinno
  

- Original 
Message - 

From: Raj 
Moodley 

To: [EMAIL PROTECTED] 


Sent: Monday, July 
18, 2005 2:54 AM

Subject: 
shape_calc.py

 
    Hi Nathan, 
wanted to find out what is shape_calc.py 
about? Am a newbie.
 
Kind 
regards
 
Raj 
Moodley
 

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


[Tutor] Which is safer and easier to code, raw_input or int(raw_input))?

2005-07-18 Thread Nathan Pinno



Hi all,
 
The subject line says it all. What's the answer?
 
Let's let everyone talk about this.
 
Nathan Pinno.

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


Re: [Tutor] Which is safer and easier to code, raw_input or int(raw_input))?

2005-07-18 Thread Nathan Pinno




  Luke and all,
   
  Anyone interested in helping me code that MasterMind-like game? I sure 
  could use the help. 
   
  Right now I'm taking time to write a program that will automatically show 
  various combos (eg a0 and x3) so that I can figure out all the various combos, 
  so that I don't miss any.
   
  Nathan Pinno
  
- Original Message - 
From: 
luke 
To: Nathan Pinno 
Sent: Monday, July 18, 2005 11:44 
AM
Subject: Re: [Tutor] Which is safer and 
easier to code,raw_input or int(raw_input))?

tmp = raw_input("hello, enter a number: 
")
try:
    tmp = int(tmp)
except ValueError:
    print "sorry that wasn't a 
number"

  - Original Message - 
  From: 
  Nathan Pinno 
  To: tutor@python.org 
  Sent: Monday, July 18, 2005 12:00 
  PM
  Subject: [Tutor] Which is safer and 
  easier to code,raw_input or int(raw_input))?
  
  Hi all,
   
  The subject line says it all. What's the answer?
   
  Let's let everyone talk about this.
   
  Nathan Pinno.
  
  
  

  ___Tutor 
  maillist  -  Tutor@python.orghttp://mail.pythonorg/mailman/listinfo/tutor

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


Re: [Tutor] shape_calc.py

2005-07-20 Thread Nathan Pinno
  Alberto,

  Sounds great. Go right ahead, and if you have any ideas for any programs 
or modifications from the apps at my Download page at 
http://www.npinnowebsite.ca/download.htm, feel free to send them also.

  Nathan
  - Original Message - 
  From: "Alberto Troiano" <[EMAIL PROTECTED]>
  To: <[EMAIL PROTECTED]>
  Sent: Monday, July 18, 2005 12:40 PM
  Subject: Re: [Tutor] shape_calc.py


  > Hey Nathan. I was watching your app and it seems like it's not finished 
yet.
  > Do you take constructive critics?
  >
  > First of all, the app only run once, so if I want to calc another area, 
I'll
  > have to run the prog again and that's not pretty nice
  >
  > Second, have you considered using GUI to make this app? Maybe show the
  > figure with its sizes or something like that
  >
  > I can send you the modifications I have made to your code if you're
  > interested. Don't mean to correct you or to stole your app, only 
suggestions
  > and ideas
  >
  > Best Regards to you
  >
  > Alberto
  >
  >>From: "Nathan Pinno" <[EMAIL PROTECTED]>
  >>To: "Raj Moodley" <[EMAIL PROTECTED]>
  >>CC: tutor@python.org
  >>Subject: Re: [Tutor] shape_calc.py
  >>Date: Mon, 18 Jul 2005 10:05:32 -0600
  >>
  >>   Raj,
  >>
  >>   My original interest was for school, now I use it to develop games 
and
  >>apps. I work at McDonalds Restaurant as Crew. I have developed another 
app
  >>called mini_calc and a game called Guess the Number; and was working on
  >>Giant Calculator, but gave up on it. I am also working on a 
MasterMind-like
  >>game, but it giving me headaches :).
  >>
  >>   Nathan Pinno.
  >>   P.S. Enjoy the shape_calc. You can find Mini_calc and Guess the 
Number
  >>on my site at this address: http://www.npinnowebsite.ca/download.htm.
  >> - Original Message -
  >> From: Raj Moodley
  >> To: 'Nathan Pinno'
  >> Sent: Monday, July 18, 2005 9:56 AM
  >> Subject: RE: shape_calc.py
  >>
  >>
  >> Hi Nathan, thanks for the email, please send it to me, would like 
to
  >>improve my understanding.
  >>
  >>
  >>
  >> What do u do? What's your interest in Python? Have you developed 
any
  >>other apps using Python?
  >>
  >>
  >>
  >> Kind regards
  >>
  >>
  >>
  >> Raj Moodley
  >>
  >>
  >>
  >>
  >>
  >>
  >> From: Nathan Pinno [mailto:[EMAIL PROTECTED]
  >> Sent: 18 July 2005 03:41 PM
  >> To: Raj Moodley
  >> Cc: tutor@python.org
  >> Subject: Re: shape_calc.py
  >>
  >>
  >>
  >>   Raj,
  >>
  >>
  >>
  >>   Shape_calc is a calculator for finding information about shapes,
  >>e.g. perimeter, area, and so forth.
  >>
  >>
  >>
  >>   HTH (Hope This Helps),
  >>
  >>   Nathan Pinno
  >>
  >> - Original Message -
  >>
  >> From: Raj Moodley
  >>
  >> To: [EMAIL PROTECTED]
  >>
  >> Sent: Monday, July 18, 2005 2:54 AM
  >>
  >> Subject: shape_calc.py
  >>
  >>
  >>
  >> Hi Nathan, wanted to find out what is shape_calc.py about? Am a
  >>newbie.
  >>
  >>
  >>
  >> Kind regards
  >>
  >>
  >>
  >> Raj Moodley
  >>
  >>
  >>
  >>___
  >>Tutor maillist  -  Tutor@python.org
  >>http://mail.python.org/mailman/listinfo/tutor
  >
  >
  > Gaucho
  >
  >
  >
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Thanks.

2005-07-26 Thread Nathan Pinno



Thanks all for helping me. Thanks to the group, I have figured out a way to 
make Giant Calculator and any program repeat until the user wants to exit.
 
Thanks again,
Nathan Pinno
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I make Python draw?

2005-07-27 Thread Nathan Pinno



How do I make Python draw a shape? e.g. a triangle Is there a specific 
module that I have to call, or what is the command(s)?
 
Thanks,
Nathan Pinno
 
P.S. Knowing this will help me make my shape_calc program 
better.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I go about this?

2005-07-27 Thread Nathan Pinno



Hi all,
 
How do I go about the following: I want to write a program that will print 
two lists one after another, then show all the available possibilities for 
matches e.g a0 and x0.
 
Here is what I have so far:
 
lista = [x0, x1, x2, x3]listb = [a0, a1, a2, a3]print 
listaprint listb
Thanks for the help,
Nathan Pinno
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I go about this?

2005-07-27 Thread Nathan Pinno



Luis and all,
 
I want to more than matching, I am trying to find all the available combos, 
e.g a1 == x1 or a1 == x2 or a1 != x1.
 
HTH,
Nathan Pinno 
 
I also noticed you forgot the a[1] == b[1]. (grin) :)
 
- Original Message - 

  From: 
  Luis N 
  To: tutor@python.org 
  Sent: Wednesday, July 27, 2005 3:01 
  PM
  Subject: Re: [Tutor] How do I go about 
  this?
  On 7/27/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:
  
  
Hi all,
 
How do I go about the following: I want to write a program that will 
print two lists one after another, then show all the available possibilities 
for matches e.g a0 and x0.
 
Here is what I have so far:
 
lista = [x0, x1, x2, x3]listb = [a0, a1, a2, a3]print 
listaprint listb
Thanks for the help,
Nathan Pinno
  Hi,Could you give some additional information as to what 
  you intend to do? If you are strictly matching, by position within the lists, 
  such that you would print the list elements only if: for x in 
  range(min(len(lista),len(listb))):    a = 
  lista[x]    b = listb[x]    if a == 
  b:    print a, bthat is 
  easy, however, if you want to match more complex patterns, or wish to match 
  list elements not in the same position then the complexity of the task 
  increases.
  
  

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


Re: [Tutor] How do I make Python draw?

2005-07-27 Thread Nathan Pinno
Thanks. Will ask if I have any more questions. Maybe I won't have to go to 
Visual Basic to write my games. Maybe Python will do the trick.

Thanks again.
Nathan Pinno
- Original Message - 
From: "Danny Yoo" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>
Cc: 
Sent: Wednesday, July 27, 2005 3:04 PM
Subject: Re: [Tutor] How do I make Python draw?


>
>
> On Wed, 27 Jul 2005, Nathan Pinno wrote:
>
>> How do I make Python draw a shape? e.g. a triangle Is there a specific
>> module that I have to call, or what is the command(s)?
>
> Hi Nathan,
>
> If you'd like to start doing graphical stuff, you might want to look at
> the Tkinter module.
>
>http://www.python.org/doc/lib/module-Tkinter.html
>
> There's an introduction to it here:
>
>http://www.pythonware.com/library/tkinter/introduction/
>
>
> Just to whet your appetite, here's a quick-and-dirty demo program that
> should draw a triangle for you:
>
> ##
> """Draws a triangle on a Tkinter canvas."""
>
> from Tkinter import *
> canvas = Canvas()
> canvas.create_polygon([(1, 1), (1, 200), (100, 100)])
> canvas.pack()
> canvas.update_idletasks()
> ##
>
>
> If you want to do more sophisticated graphics stuff, there are alternative
> packages, like pygame:
>
>http://www.pygame.org/news.html
>
>
> If you have more questions, please feel free to ask!
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Why does this NameError appear?

2005-07-27 Thread Nathan Pinno



Here is the code:
lista = [x0, x1, x2, x3]listb = [a0, a1, a2, a3]print 
listaprint listbprint match (lista, listb)
 
And here is the error:
Traceback (most recent call last):  File "D:\Python22\matches.py", 
line 1, in ?    lista = [x0, x1, x2, x3]NameError: name 
'x0' is not defined
Thanks in advance,
Nathan Pinno
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I make Python draw?

2005-07-27 Thread Nathan Pinno
Luke,

Thanks for the reminder. Though I might try Java, but having problems with 
errors left, right and center.

G2G,
Nathan
- Original Message - 
From: "luke" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>; "Danny Yoo" 
<[EMAIL PROTECTED]>
Cc: 
Sent: Wednesday, July 27, 2005 4:36 PM
Subject: Re: [Tutor] How do I make Python draw?


>
>> Thanks. Will ask if I have any more questions. Maybe I won't have to go 
>> to
>> Visual Basic to write my games. Maybe Python will do the trick.
> Oh my god.
> Don't ever compare Python to Basic on a python mailing list.
> You'll get eaten alive ;-)
>
> Seriously though,
> If you take the time to learn PyGame, it's about the easiest and
> best way to write a game in any language (from scratch that is.)
> I highly recommend it.
> In fact I'm writing a PyGame game right now.
> If you're interested in seeing the source at some point,
> Just ask.
> Although I won't send it just yet because it has no drawing code ATM.
> Just game logic.
>
> Hope ThAt HeLPs.
> Don't ever resort to Visual Basic.
> If you think something would be easier in VB then ask us
> and we will tell you how to do it in Python.
> VB is not a good language to learn because it
> is the complete opposite of every other programming language.
>
> I really can't think of a reason to use VB over Python, C++ or Java.
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I make Python draw?

2005-07-27 Thread Nathan Pinno
Pygame looks solid. I'm sold on it. Maybe I'll be able to code my Guess the 
Number Sequence Game with it using Python.
- Original Message - 
From: "Danny Yoo" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>
Cc: 
Sent: Wednesday, July 27, 2005 3:04 PM
Subject: Re: [Tutor] How do I make Python draw?


>
>
> On Wed, 27 Jul 2005, Nathan Pinno wrote:
>
>> How do I make Python draw a shape? e.g. a triangle Is there a specific
>> module that I have to call, or what is the command(s)?
>
> Hi Nathan,
>
> If you'd like to start doing graphical stuff, you might want to look at
> the Tkinter module.
>
>http://www.python.org/doc/lib/module-Tkinter.html
>
> There's an introduction to it here:
>
>http://www.pythonware.com/library/tkinter/introduction/
>
>
> Just to whet your appetite, here's a quick-and-dirty demo program that
> should draw a triangle for you:
>
> ##
> """Draws a triangle on a Tkinter canvas."""
>
> from Tkinter import *
> canvas = Canvas()
> canvas.create_polygon([(1, 1), (1, 200), (100, 100)])
> canvas.pack()
> canvas.update_idletasks()
> ##
>
>
> If you want to do more sophisticated graphics stuff, there are alternative
> packages, like pygame:
>
>http://www.pygame.org/news.html
>
>
> If you have more questions, please feel free to ask!
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I go about this? [was Re: Who uses input()? [was Re: question on "input"]]

2005-07-27 Thread Nathan Pinno
I first posted my question in this post, but no one seemed to answer me.
- Original Message - 
From: "Nathan Pinno" <[EMAIL PROTECTED]>
To: "Danny Yoo" <[EMAIL PROTECTED]>
Cc: ; "Terry Reedy" <[EMAIL PROTECTED]>
Sent: Monday, July 18, 2005 7:36 AM
Subject: Re: [Tutor] Who uses input()? [was Re: question on "input"]


>  Danny,
>
>  It sure did, though I wish there was an easier way of coding it than
> int(raw_input())! Any ideas would gladly be appreciated.
>
>  By the way, is there any code floating out there that can show how many
> possible mixtures there are, e.g. for x0, x1, x2, x3, and a0, a1, a2, and 
> a3
> for example. If there is, show me it, please. I'm getting confused writing
> my MasterMind and don't want to screw up bad, e.g. repeat the same answer 
> in
> a different way.
>
>  Thanks,
>  Nathan Pinno.
>  - Original Message - 
>  From: "Danny Yoo" <[EMAIL PROTECTED]>
>  To: "Nathan Pinno" <[EMAIL PROTECTED]>
>  Cc: "Terry Reedy" <[EMAIL PROTECTED]>; 
>  Sent: Monday, July 18, 2005 2:14 AM
>  Subject: Re: [Tutor] Who uses input()? [was Re: question on "input"]
>
>
>  >
>  >
>  > On Mon, 18 Jul 2005, Nathan Pinno wrote:
>  >
>  >> I find it easier to remember and faster to code than int(raw_input()).
>  >> The faster I can code a program, the better in my opinion. So what if
> it
>  >> has a few bugs, I fix them gradually.
>  >
>  > Hi Nathan
>  >
>  > You're right, just as long as we're writing programs that are only 
> meant
>  > to be used by ourselves, and as long as we're sure that it's not 
> talking
>  > to the outside world.  The driving issue behind getting paranoid is
> this:
>  > it's getting much easier to write programs that we think might be just
> for
>  > ourselves, but which become useful for others.
>  >
>  > And as soon as we write programs that other people are going to use, we
>  > really do have to play by a different set of rules than just ease of
>  > programming.  Some folks were casual about eval(), and look what
> happened
>  > to them:
>  >
>  >http://gulftech.org/?node=research&article_id=00088-07022005
>  >
>  > They should have known better.
>  >
>  > This problem is not exclusive to programmers in PHP:  programmers in
>  > Python make the same kind of mistakes.  As a concrete example, take a
> look
>  > at the comments about the deprecated "SimpleCookie" and "SerialCookie"
>  > functions:
>  >
>  >http://www.python.org/doc/lib/module-Cookie.html
>  >
>  > Again, they should have known better.  And we should know better.
>  >
>  > So we do have a responsibility to state up front that using 'eval' (or
>  > things that call 'eval' for us) is convenient, but it's not safe.
> That's
>  > why we bug about it every so often.
>  >
>  >
>  > Hope this helps!
>  >
>  >
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] I'm stumped.

2005-07-27 Thread Nathan Pinno



How do I split the list members up in the following code? What am I 
forgetting?
 
lista = []listb = []lista = raw_input("Enter lista, separated by 
commas: ")listb = raw_input("Enter listb, separated by commas: ")print 
listaprint listbfor item in lista:   for other in 
listb:  print item,other
 
Thanks in advance,
Nathan Pinno
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I go about this? [was Re: Who uses input()? [was Re: question on "input"]]

2005-07-27 Thread Nathan Pinno
Here's part of what I'm looking for (got it from a Python program):
a b
a 2
a 5
a 6
1 b
1 2
1 5
1 6
3 b
3 2
3 5
3 6
4 b
4 2
4 5
4 6
I want to see also !=, ==, and, & nor combos also. 0 != 2 for an example.

- Original Message - 
From: "Danny Yoo" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>
Cc: "Tutor" 
Sent: Wednesday, July 27, 2005 5:39 PM
Subject: Re: [Tutor] How do I go about this? [was Re: Who uses input()? [was 
Re: question on "input"]]


>
>
>> I first posted my question in this post, but no one seemed to answer me.
>> >
>> >  It sure did, though I wish there was an easier way of coding it than
>> > int(raw_input())! Any ideas would gladly be appreciated.
>
> Hi Nathan,
>
> About the question about int(raw_input()) being a bit verbose, Brian did
> mention that we can define helper functions to make things less painful.
> Personal function definitions like this can be very useful: we don't
> always have to work at a primitive level, but can build on larger
> concepts.
>
> His suggested get_int() function:
>
>http://mail.python.org/pipermail/tutor/2005-July/039855.html
>
> looks a bit big at first, but we can define it once, store it in a
> personal library somewhere, and then it'll be available for us from then
> on.
>
>
>> > By the way, is there any code floating out there that can show how
>> > many possible mixtures there are, e.g. for x0, x1, x2, x3, and a0, a1,
>> > a2, and a3 for example.
>
> I think people were a little confused what you meant here; can you give us
> more ideas of what this is for?  "Mixture" in English means so many things
> that it's hard to give concrete answers without seeing more what you mean.
>
>
> Good luck!
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I'm stumped.

2005-07-27 Thread Nathan Pinno
Thanks. Now it basically works. Now I just have to improve it.
- Original Message - 
From: "Alan G" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>; 
Sent: Wednesday, July 27, 2005 6:06 PM
Subject: Re: [Tutor] I'm stumped.


> Try the split method:
> 
>>>> '1,2,3,4'.split(',')
> ['1', '2', '3', '4']
>>>>
> 
> Alan G
> 
> - Original Message - 
> From: "Nathan Pinno" <[EMAIL PROTECTED]>
> To: 
> Sent: Thursday, July 28, 2005 12:17 AM
> Subject: [Tutor] I'm stumped.
> 
> 
> How do I split the list members up in the following code? What am I 
> forgetting?
> 
> lista = []
> listb = []
> lista = raw_input("Enter lista, separated by commas: ")
> listb = raw_input("Enter listb, separated by commas: ")
> print lista
> print listb
> for item in lista:
>   for other in listb:
>  print item,other
> 
> Thanks in advance,
> Nathan Pinno 
> 
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: we won't eat VB programmers for lunch [Was: How doI make Python draw?]

2005-07-27 Thread Nathan Pinno
Now that's worth the mention of VB. Glad I have Python, or many of my ideas 
would stay in my head...hehehe
- Original Message - 
From: "luke" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "Tutor" 
Sent: Wednesday, July 27, 2005 6:28 PM
Subject: Re: [Tutor] OT: we won't eat VB programmers for lunch [Was: How doI 
make Python draw?]


> hehe.
> <3 malbolge.
>
> Yeah, I actually learned basic as my first language...
> I don't mind it.
> I just don't like it all that much.
>
> ___
> 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] I'm stumped.

2005-07-27 Thread Nathan Pinno
It works. The program will be found on my webpage at it's new address 
http://falcon3166.tripod.com in the Downloads page.
- Original Message - 
From: "Nathan Pinno" <[EMAIL PROTECTED]>
To: "Alan G" <[EMAIL PROTECTED]>; 
Sent: Wednesday, July 27, 2005 6:33 PM
Subject: Re: [Tutor] I'm stumped.


> Thanks. Now it basically works. Now I just have to improve it.
> - Original Message ----- 
> From: "Alan G" <[EMAIL PROTECTED]>
> To: "Nathan Pinno" <[EMAIL PROTECTED]>; 
> Sent: Wednesday, July 27, 2005 6:06 PM
> Subject: Re: [Tutor] I'm stumped.
>
>
>> Try the split method:
>>
>>>>> '1,2,3,4'.split(',')
>> ['1', '2', '3', '4']
>>>>>
>>
>> Alan G
>>
>> - Original Message - 
>> From: "Nathan Pinno" <[EMAIL PROTECTED]>
>> To: 
>> Sent: Thursday, July 28, 2005 12:17 AM
>> Subject: [Tutor] I'm stumped.
>>
>>
>> How do I split the list members up in the following code? What am I
>> forgetting?
>>
>> lista = []
>> listb = []
>> lista = raw_input("Enter lista, separated by commas: ")
>> listb = raw_input("Enter listb, separated by commas: ")
>> print lista
>> print listb
>> for item in lista:
>>   for other in listb:
>>  print item,other
>>
>> Thanks in advance,
>> Nathan Pinno
>>
>>
> ___
> 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] OT: we won't eat VB programmers for lunch [Was: How doImake Python draw?]

2005-07-29 Thread Nathan Pinno
I got it Alan. It was good. Thanks.
- Original Message - 
From: "Alan G" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>; "Tutor" 
Sent: Thursday, July 28, 2005 4:15 AM
Subject: Re: [Tutor] OT: we won't eat VB programmers for lunch [Was: How 
doImake Python draw?]


> Nathan,
>
> I tried to send you a reply about using the 'turtle' module to do
> your graphics, did you receive it? I sent it from the gane news
> archive server and its not there and I haven't seen it on the group
> so I'm wondering if it ever actually went anywhere?...
>
> Alan G.
>
> - Original Message - 
> From: "Nathan Pinno" <[EMAIL PROTECTED]>
> To: "luke" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; "Tutor" 
> 
> Sent: Thursday, July 28, 2005 1:36 AM
> Subject: Re: [Tutor] OT: we won't eat VB programmers for lunch [Was: How 
> doImake Python draw?]
>
>
>> Now that's worth the mention of VB. Glad I have Python, or many of my 
>> ideas would stay in my head...hehehe
>> - Original Message - 
>> From: "luke" <[EMAIL PROTECTED]>
>> To: <[EMAIL PROTECTED]>; "Tutor" 
>> Sent: Wednesday, July 27, 2005 6:28 PM
>> Subject: Re: [Tutor] OT: we won't eat VB programmers for lunch [Was: How 
>> doI make Python draw?]
>>
>>
>>> hehe.
>>> <3 malbolge.
>>>
>>> Yeah, I actually learned basic as my first language...
>>> I don't mind it.
>>> I just don't like it all that much.
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>>
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I get rid of blank space when running a program I've coded?

2005-07-30 Thread Nathan Pinno



Hi all,
 
I'll be brief. I always get a blank line whenever I run my Python programs 
that I've coded. How can I get rid of it. It's kind of annoying to press the 
spacebar in order to return to >>> in IDLE or the C:\ prompt in 
DOS.
 
Thanks,
Nathan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I get rid of blank space when running a program I'vecoded?

2005-07-30 Thread Nathan Pinno



I meant the return key, not the spacebar. Sorry for the mix-up.

  - Original Message - 
  From: 
  Nathan 
  Pinno 
  To: tutor@python.org 
  Sent: Saturday, July 30, 2005 3:50 
  PM
  Subject: [Tutor] How do I get rid of 
  blank space when running a program I'vecoded?
  
  Hi all,
   
  I'll be brief. I always get a blank line whenever I run my Python 
  programs that I've coded. How can I get rid of it. It's kind of annoying to 
  press the spacebar in order to return to >>> in IDLE or the C:\ 
  prompt in DOS.
   
  Thanks,
  Nathan
  
  

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


[Tutor] What's the invalid synax? Error message and code supplied.

2005-07-30 Thread Nathan Pinno



Here's the message:
  File "D:\Python22\prog4.py", line 19    while 
option != 9:    ^SyntaxError: 
invalid syntax
And the code:
#This program finds the area and perimeter of circles, rectangles, and 
squares.def menu():    print '1) Area 
(Circle)'    print '2) Area 
(Rectangle)'    print '3) Area 
(Square)'    print '4) Perimeter 
(Circle)'    print '5) Perimeter 
(Square)'    print '6) Perimeter 
(Rectangle)'    print '9) Exit'
 
import mathprint 'By Nathan Pinno'print 'ID# 
2413448'printprint 'Program 4 - Functions'printmenu()option 
= int(raw_input('Option (1,2,3,4,5,6,9): ')while option != 
9:    if option == 
1:    r = int(raw_input('Radius: 
')    print 'The area of the circle = 
',pi*(r**2)    option = 
int(raw_input('Option (1,2,3,4,5,6,9): ')    elif option == 
2:    l = int(raw_input('Length: 
')    w = int(raw_input('Width: 
')    print 'The area of the 
rectangle = ',l*w    option = 
int(raw_input('Option (1,2,3,4,5,6,9): ')    elif option == 
3:    s = int(raw_input('Side: 
')    print 'The area of a square = 
',s**2    option = 
int(raw_input('Option (1,2,3,4,5,6,9): ')    elif option == 
4:    d = int(raw_input('Diameter: 
')    print 'The perimeter of the 
circle = ',pi*d    option = 
int(raw_input('Option (1,2,3,4,5,6,9): ')    elif option == 
5:    l = int(raw_input('Length: 
')    w = int(raw_input('Width: 
')    print 'The perimeter of the 
rectangle = ',(2*l)+(2*w)    option = 
int(raw_input('Option (1,2,3,4,5,6,9): ')    elif option == 
6:    s = int(raw_input('Side: 
')    print 'The perimeter of a 
square = ',s*4    option = 
int(raw_input('Option (1,2,3,4,5,6,9): ')    
else:    print 'That is not an 
option. Please choose an option.'    
option = int(raw_input('Option (1,2,3,4,5,6,9): ')print 
'Goodbye.'
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What's the invalid synax? Error message and codesupplied.

2005-07-30 Thread Nathan Pinno
There is only 1 parenthesis on the prior line, but lots of commas.
- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Saturday, July 30, 2005 5:22 PM
Subject: Re: [Tutor] What's the invalid synax? Error message and 
codesupplied.


>
> I'd count the parenthesis on the prior line:
>
>
> option = int(raw_input('Option (1,2,3,4,5,6,9): ')
> while option != 9:
>
>
> Also when you notice that you are copying and pasting the same line over 
> and
> over, it may be time to think about reorganizing the code a little bit 
> (Once
> you have it working).
>
> Happy Debugging
>
> --Todd
>
>
> On Saturday 30 July 2005 06:19 pm, Nathan Pinno wrote:
>> Here's the message:
>>   File "D:\Python22\prog4.py", line 19
>> while option != 9:
>> ^
>> SyntaxError: invalid syntax
>>
>> And the code:
>> #This program finds the area and perimeter of circles, rectangles, and
>> squares. def menu():
>> print '1) Area (Circle)'
>> print '2) Area (Rectangle)'
>> print '3) Area (Square)'
>> print '4) Perimeter (Circle)'
>> print '5) Perimeter (Square)'
>> print '6) Perimeter (Rectangle)'
>> print '9) Exit'
>>
>> import math
>> print 'By Nathan Pinno'
>> print 'ID# 2413448'
>> print
>> print 'Program 4 - Functions'
>> print
>> menu()
>> option = int(raw_input('Option (1,2,3,4,5,6,9): ')
>> while option != 9:
>> if option == 1:
>> r = int(raw_input('Radius: ')
>> print 'The area of the circle = ',pi*(r**2)
>> option = int(raw_input('Option (1,2,3,4,5,6,9): ')
>> elif option == 2:
>> l = int(raw_input('Length: ')
>> w = int(raw_input('Width: ')
>> print 'The area of the rectangle = ',l*w
>> option = int(raw_input('Option (1,2,3,4,5,6,9): ')
>> elif option == 3:
>> s = int(raw_input('Side: ')
>> print 'The area of a square = ',s**2
>> option = int(raw_input('Option (1,2,3,4,5,6,9): ')
>> elif option == 4:
>> d = int(raw_input('Diameter: ')
>> print 'The perimeter of the circle = ',pi*d
>> option = int(raw_input('Option (1,2,3,4,5,6,9): ')
>> elif option == 5:
>> l = int(raw_input('Length: ')
>> w = int(raw_input('Width: ')
>> print 'The perimeter of the rectangle = ',(2*l)+(2*w)
>> option = int(raw_input('Option (1,2,3,4,5,6,9): ')
>> elif option == 6:
>> s = int(raw_input('Side: ')
>> print 'The perimeter of a square = ',s*4
>> option = int(raw_input('Option (1,2,3,4,5,6,9): ')
>> else:
>> print 'That is not an option. Please choose an option.'
>> option = int(raw_input('Option (1,2,3,4,5,6,9): ')
>> print 'Goodbye.'
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I make a Python program keep repeating?

2005-07-30 Thread Nathan Pinno



Hi all,
 
How do I make a program keep repeating until the user is done with 
it?
 
Thanks,
Nathan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] When I run this code, it just keeps repeating.

2005-07-30 Thread Nathan Pinno



When I run the following code it just keeps repeating. Here is a screen 
shot showing what I mean:
Mini CalculatorBy Nathan Pinno
 
CALCULATE MENU1) Add2) Subraction3) Multiplication4) 
Division w/o remainder5) Division with remaider6) Exponation7) 
Square roots9) ExitOption: 5First number:4Second number:24 / 
2 =  2  R  0First number:3Second number:63 / 6 
=  0  R  3First number:5Second number:65 / 6 =  
0  R  5First number:
 
Here is the relevant code:
# This is a small calculator.def menu():    print 
"CALCULATE MENU"    print "1) Add"    
print "2) Subraction"    print "3) 
Multiplication"    print "4) Division w/o 
remainder"    print "5) Division with 
remaider"    print "6) Exponation"    
print "7) Square roots"    print "9) Exit"
 
def cal():    global cal_opt    
cal_opt = int(raw_input("Option: "))
 
print "Mini Calculator"print "By Nathan 
Pinno"printmenu()cal()while cal_opt != 9:    
if cal_opt == 1:    X = input("First 
number:" )    Y = input("Second 
number:" )    print X, "+", Y, "= ",X 
+ Y    elif cal_opt == 
2:    X = input("First number:" 
)    Y = input("Second number:" 
)    print X, "-", Y, "= ",X - 
Y    elif cal_opt == 
3:    X = input("First number:" 
)    Y = input("Second number:" 
)    print X, "*", Y, "= ",X * 
Y    elif cal_opt == 
4:    X = input("First number:" 
)    Y = input("Second number:" 
)    if Y == 
0:    print 
"Division by zero ot 
allowed!"    
Y = input("Second number:" )    
else:    
print X, "/", Y, "= ",X / Y    elif cal_opt == 
5:    X = input("First number:" 
)    Y = input("Second number:" 
)    if Y == 
0:    print 
"Division by zero ot 
allowed!"    
Y = input("Second number:" )    
else:    
print X, "/", Y, "= ",X / Y," R ", X % Y    elif cal_opt == 
6:    X = input("First number:" 
)    Y = input("Power:" 
)    print X, "**", Y, "= 
",X**Y    elif cal_opt == 
7:    X = input("Number to find the 
square root of:" )    print "The 
square root of", X, " = ",X**0.5    
else:    print "That's not an option. 
Try again."    
menu()    cal()print 
"Goodbye"
 
How do I stop this, and make it go back to the main menu?
 
Thanks in advance,
Nathan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When I run this code, it just keeps repeating.

2005-07-30 Thread Nathan Pinno
Thanks Todd. Can you please look at my other messages that you haven't 
answered, and see what's wrong with them, or what the answer is.
- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Saturday, July 30, 2005 8:10 PM
Subject: Re: [Tutor] When I run this code, it just keeps repeating.


> Looks like you are making some pretty good progress.
>
> The short answer to your question is that the menu & user input need to be
> inside the while loop.  That way cal_opt has a chance to change value 
> before
> it gets evaluated by the while loop again.
>
> Another comment - the global cal_opt is considered evil by many.  Better 
> would
> be:
>
> def cal():
>   return  int(raw_input("Option: "))
>
> print "Mini Calculator"
> print "By Nathan Pinno"
> print
>
> while cal_opt != 9:
>   menu()
>   cal_opt=cal()
>
>   if cal_opt == 1:
> X = input("First number:" )
> Y = input("Second number:" )
> print X, "+", Y, "= ",X + Y
>
>   
>
>
> Keep hacking away at it...  you're making good progress.
>
> --Todd
>
>
> On Saturday 30 July 2005 09:55 pm, Nathan Pinno wrote:
>> When I run the following code it just keeps repeating. Here is a screen
>> shot showing what I mean: Mini Calculator
>> By Nathan Pinno
>>
>> CALCULATE MENU
>> 1) Add
>> 2) Subraction
>> 3) Multiplication
>> 4) Division w/o remainder
>> 5) Division with remaider
>> 6) Exponation
>> 7) Square roots
>> 9) Exit
>> Option: 5
>> First number:4
>> Second number:2
>> 4 / 2 =  2  R  0
>> First number:3
>> Second number:6
>> 3 / 6 =  0  R  3
>> First number:5
>> Second number:6
>> 5 / 6 =  0  R  5
>> First number:
>>
>> Here is the relevant code:
>> # This is a small calculator.
>> def menu():
>> print "CALCULATE MENU"
>> print "1) Add"
>> print "2) Subraction"
>> print "3) Multiplication"
>> print "4) Division w/o remainder"
>> print "5) Division with remaider"
>> print "6) Exponation"
>> print "7) Square roots"
>> print "9) Exit"
>>
>> def cal():
>> global cal_opt
>> cal_opt = int(raw_input("Option: "))
>>
>> print "Mini Calculator"
>> print "By Nathan Pinno"
>> print
>> menu()
>> cal()
>> while cal_opt != 9:
>> if cal_opt == 1:
>> X = input("First number:" )
>> Y = input("Second number:" )
>> print X, "+", Y, "= ",X + Y
>> elif cal_opt == 2:
>> X = input("First number:" )
>> Y = input("Second number:" )
>> print X, "-", Y, "= ",X - Y
>> elif cal_opt == 3:
>> X = input("First number:" )
>> Y = input("Second number:" )
>> print X, "*", Y, "= ",X * Y
>> elif cal_opt == 4:
>> X = input("First number:" )
>> Y = input("Second number:" )
>> if Y == 0:
>> print "Division by zero ot allowed!"
>> Y = input("Second number:" )
>> else:
>> print X, "/", Y, "= ",X / Y
>> elif cal_opt == 5:
>> X = input("First number:" )
>> Y = input("Second number:" )
>> if Y == 0:
>> print "Division by zero ot allowed!"
>> Y = input("Second number:" )
>> else:
>> print X, "/", Y, "= ",X / Y," R ", X % Y
>> elif cal_opt == 6:
>> X = input("First number:" )
>> Y = input("Power:" )
>> print X, "**", Y, "= ",X**Y
>> elif cal_opt == 7:
>> X = input("Number to find the square root of:" )
>> print "The square root of", X, " = ",X**0.5
>> else:
>> print "That's not an option. Try again."
>> menu()
>> cal()
>> print "Goodbye"
>>
>> How do I stop this, and make it go back to the main menu?
>>
>> Thanks in advance,
>> Nathan
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Now what do I do?(was Re: When I run this code, it just keeps repeating.)

2005-07-30 Thread Nathan Pinno
Here is another screen shot:
Mini Calculator
By Nathan Pinno

CALCULATE MENU
1) Add
2) Subraction
3) Multiplication
4) Division w/o remainder
5) Division with remaider
6) Exponation
7) Square roots
9) Exit
Option: 3
First number:4
Second number:6
4 * 6 =  24
CALCULATE MENU
1) Add
2) Subraction
3) Multiplication
4) Division w/o remainder
5) Division with remaider
6) Exponation
7) Square roots
9) Exit
Option: 9
That's not an option. Try again.
CALCULATE MENU
1) Add
2) Subraction
3) Multiplication
4) Division w/o remainder
5) Division with remaider
6) Exponation
7) Square roots
9) Exit
Option: 6
Goodbye

And the latest code:
# This is a small calculator.
def menu():
print "CALCULATE MENU"
print "1) Add"
print "2) Subraction"
print "3) Multiplication"
print "4) Division w/o remainder"
print "5) Division with remaider"
print "6) Exponation"
print "7) Square roots"
print "9) Exit"

def cal():
return int(raw_input("Option: "))

print "Mini Calculator"
print "By Nathan Pinno"
print
while cal_opt != 9:
menu()
cal_opt = cal()
if cal_opt == 1:
X = input("First number:" )
Y = input("Second number:" )
print X, "+", Y, "= ",X + Y
elif cal_opt == 2:
X = input("First number:" )
Y = input("Second number:" )
print X, "-", Y, "= ",X - Y
elif cal_opt == 3:
X = input("First number:" )
Y = input("Second number:" )
print X, "*", Y, "= ",X * Y
elif cal_opt == 4:
X = input("First number:" )
Y = input("Second number:" )
if Y == 0:
print "Division by zero ot allowed!"
Y = input("Second number:" )
else:
print X, "/", Y, "= ",X / Y
elif cal_opt == 5:
X = input("First number:" )
Y = input("Second number:" )
if Y == 0:
print "Division by zero ot allowed!"
Y = input("Second number:" )
else:
print X, "/", Y, "= ",X / Y," R ", X % Y
elif cal_opt == 6:
X = input("First number:" )
Y = input("Power:" )
print X, "**", Y, "= ",X**Y
elif cal_opt == 7:
X = input("Number to find the square root of:" )
print "The square root of", X, " = ",X**0.5
else:
print "That's not an option. Try again."
menu()
cal()
print "Goodbye"

Thanks in advance,
Nathan Pinno.
- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Saturday, July 30, 2005 8:10 PM
Subject: Re: [Tutor] When I run this code, it just keeps repeating.


> Looks like you are making some pretty good progress.
>
> The short answer to your question is that the menu & user input need to be
> inside the while loop.  That way cal_opt has a chance to change value 
> before
> it gets evaluated by the while loop again.
>
> Another comment - the global cal_opt is considered evil by many.  Better 
> would
> be:
>
> def cal():
>   return  int(raw_input("Option: "))
>
> print "Mini Calculator"
> print "By Nathan Pinno"
> print
>
> while cal_opt != 9:
>   menu()
>   cal_opt=cal()
>
>   if cal_opt == 1:
> X = input("First number:" )
> Y = input("Second number:" )
> print X, "+", Y, "= ",X + Y
>
>   
>
>
> Keep hacking away at it...  you're making good progress.
>
> --Todd
>
>
> On Saturday 30 July 2005 09:55 pm, Nathan Pinno wrote:
>> When I run the following code it just keeps repeating. Here is a screen
>> shot showing what I mean: Mini Calculator
cut screen shot and code
>> Thanks in advance,
>> Nathan
> ___
> 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] How do I get rid of blank space when running a program I'vecoded?

2005-07-30 Thread Nathan Pinno
I never have it. Although when I ask for option I use 
int(raw_input('Option:')) instead of raw_input('Option:'). That's usually 
near the top, but part of a while loop.
- Original Message - 
From: "Kent Johnson" <[EMAIL PROTECTED]>
Cc: 
Sent: Saturday, July 30, 2005 8:55 PM
Subject: Re: [Tutor] How do I get rid of blank space when running a program 
I'vecoded?


> Do you have a call to raw_input() at the end of your program? That will 
> make you press return to exit the program. It's useful for command-line 
> programs that you want to run by double-clicking them but you can take it 
> out if you find it annoying.
>
> Kent
>
> Nathan Pinno wrote:
>> I meant the return key, not the spacebar. Sorry for the mix-up.
>>
>> - Original Message -
>> *From:* Nathan Pinno <mailto:[EMAIL PROTECTED]>
>> *To:* tutor@python.org <mailto:tutor@python.org>
>> *Sent:* Saturday, July 30, 2005 3:50 PM
>> *Subject:* [Tutor] How do I get rid of blank space when running a
>> program I'vecoded?
>>
>> Hi all,
>>
>> I'll be brief. I always get a blank line whenever I run my Python
>> programs that I've coded. How can I get rid of it. It's kind of
>> annoying to press the spacebar in order to return to >>> in IDLE or
>> the C:\ prompt in DOS.
>>
>> Thanks,
>> Nathan
>>
>> 
>>
>> ___
>> Tutor maillist  -  Tutor@python.org <mailto:Tutor@python.org>
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>> 
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
> ___
> 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] Now what do I do?(was Re: When I run this code, it just keeps repeating.)

2005-07-30 Thread Nathan Pinno
Glad I didn't put up my mini calculator apps on my site. Would have had
complaints from people. But this thread has given me ideas on how to fix
them all, and how to fix Giant Calculator as well.
- Original Message - 
From: "Reed L. O'Brien" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>
Sent: Saturday, July 30, 2005 9:05 PM
Subject: Re: [Tutor] Now what do I do?(was Re: When I run this code, it just
keeps repeating.)


> THis help?
>
>
> # This is a small calculator.
> def menu():
>print "CALCULATE MENU"
>print "1) Add"
>print "2) Subraction"
>print "3) Multiplication"
>print "4) Division w/o remainder"
>print "5) Division with remaider"
>print "6) Exponation"
>print "7) Square roots"
>print "9) Exit"
>
> def cal():
>cal_opt = int(raw_input("Option: "))
>return cal_opt
>
> print "Mini Calculator"
> print "By Nathan Pinno"
> print
> while 1:  <== here
>menu()
>cal_opt = cal()
>if cal_opt == 1:
>X = input("First number:" )
>Y = input("Second number:" )
>print X, "+", Y, "= ",X + Y
>elif cal_opt == 2:
>X = input("First number:" )
>Y = input("Second number:" )
>print X, "-", Y, "= ",X - Y
>elif cal_opt == 3:
>X = input("First number:" )
>Y = input("Second number:" )
>print X, "*", Y, "= ",X * Y
>elif cal_opt == 4:
>X = input("First number:" )
>Y = input("Second number:" )
>if Y == 0:
>print "Division by zero ot allowed!"
>Y = input("Second number:" )
>else:
>print X, "/", Y, "= ",X / Y
>elif cal_opt == 5:
>X = input("First number:" )
>Y = input("Second number:" )
>if Y == 0:
>print "Division by zero ot allowed!"
>Y = input("Second number:" )
>else:
>print X, "/", Y, "= ",X / Y," R ", X % Y
>elif cal_opt == 6:
>X = input("First number:" )
>Y = input("Power:" )
>print X, "**", Y, "= ",X**Y
>elif cal_opt == 7:
>X = input("Number to find the square root of:" )
>print "The square root of", X, " = ",X**0.5
>elif cal_opt == 9: ##<== here
>break ###<= here
>else:
>print "That's not an option. Try again."
>menu()
>cal()
> print "Goodbye"
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with file I/O.

2005-07-30 Thread Nathan Pinno



If anyone will help me learn file I/O, it would be appreciated. I went 
through Josh Cogliani's Non-Programmer's Tutorial for Python, and I still can't 
understand it.
 
Thanks in advance,
Nathan Pinno
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cant get started

2005-07-30 Thread Nathan Pinno



This is an easy one. Go to the IDLE, I 
found it was easier. The latest Python refused to work on mine, so I'm using 
2.2.3, and it works fine.

  - Original Message - 
  From: 
  [EMAIL PROTECTED] 
  To: tutor@python.org 
  Sent: Friday, July 29, 2005 10:22 
PM
  Subject: [Tutor] cant get started
  
  it said this is for newbies but I download the 2.4 and I tried the 
  stuff it said on the tutorial like the control-z or sys.exit () I tried 
  the control-p or the python -c but it always says "'something' is not defined" 
  or " invalid syntax" where do I go or what do I do. do i go the the 
  command line or the shell cause I tried both please write me 
  back
  
  

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


Re: [Tutor] Help with file I/O.

2005-07-30 Thread Nathan Pinno
Well, you saw my password program. That was my first attempt at using file 
I/O. Thought I'd try it big time. You saw where that went.
Nathan
- Original Message - 
From: "Danny Yoo" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>
Cc: 
Sent: Sunday, July 31, 2005 12:13 AM
Subject: Re: [Tutor] Help with file I/O.


>
>
>> If anyone will help me learn file I/O, it would be appreciated. I went
>> through Josh Cogliani's Non-Programmer's Tutorial for Python, and I
>> still can't understand it.
>
> Hi Nathan,
>
> Can you point out what parts don't make sense?  We can try to explain
> better, but we can only do so if you either show us code, or quote the
> part of the tutorial that mystifies you.  If we can talk about it more,
> maybe we'll be able to figure out what part you're getting stuck on.
>
>
> Good luck!
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I make a Python program keep repeating?

2005-07-31 Thread Nathan Pinno
I'd post another code, but I've already figured it out, thanks to help on 
the mini calc program.
- Original Message - 
From: "Alan G" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>; 
Sent: Sunday, July 31, 2005 2:03 AM
Subject: Re: [Tutor] How do I make a Python program keep repeating?


>> How do I make a program keep repeating until the user is done with it?
>
> The math shapes example you just sent in with a syntax area does just 
> that.
>
> What else do you need?
>
> Alan g
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with file I/O.

2005-07-31 Thread Nathan Pinno
Here's my work. I call it filewriter.
The code:
file = raw_input("File name please: ")
f = file(file, "r")
for line in f.readlines():
print line
f.close()

Will it do the trick?

Nathan
- Original Message - 
From: "Danny Yoo" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>
Cc: 
Sent: Sunday, July 31, 2005 12:22 AM
Subject: Re: [Tutor] Help with file I/O.


>
>
> On Sun, 31 Jul 2005, Nathan Pinno wrote:
>
>> Well, you saw my password program. That was my first attempt at using
>> file I/O. Thought I'd try it big time. You saw where that went.
>
> Ok, let's take a look.  It was from this message, right?
>
>http://mail.python.org/pipermail/tutor/2005-July/039478.html
>
> That was such a while back that I think you probably learned a lot since
> then, and I think a few of the issues there were less about I/O and more
> about just general programming.
>
> Let's try a few things, just to see why you're getting stuck.  Can you
> write a program that reads in a file, and just prints all of its lines out
> to screen?
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with file I/O.

2005-07-31 Thread Nathan Pinno
Just ran the code and got the following error:
File name please: news.text
Traceback (most recent call last):
  File "D:\Python22\filewriter.py", line 2, in ?
f = file(file, "r")
TypeError: 'str' object is not callable

Why isn't it callable? Help me understand.
----- Original Message - 
From: "Nathan Pinno" <[EMAIL PROTECTED]>
To: "Danny Yoo" <[EMAIL PROTECTED]>
Cc: 
Sent: Sunday, July 31, 2005 2:29 PM
Subject: Re: [Tutor] Help with file I/O.


> Here's my work. I call it filewriter.
> The code:
> file = raw_input("File name please: ")
> f = file(file, "r")
> for line in f.readlines():
>print line
> f.close()
>
> Will it do the trick?
>
> Nathan
> - Original Message - 
> From: "Danny Yoo" <[EMAIL PROTECTED]>
> To: "Nathan Pinno" <[EMAIL PROTECTED]>
> Cc: 
> Sent: Sunday, July 31, 2005 12:22 AM
> Subject: Re: [Tutor] Help with file I/O.
>
>
>>
>>
>> On Sun, 31 Jul 2005, Nathan Pinno wrote:
>>
>>> Well, you saw my password program. That was my first attempt at using
>>> file I/O. Thought I'd try it big time. You saw where that went.
>>
>> Ok, let's take a look.  It was from this message, right?
>>
>>http://mail.python.org/pipermail/tutor/2005-July/039478.html
>>
>> That was such a while back that I think you probably learned a lot since
>> then, and I think a few of the issues there were less about I/O and more
>> about just general programming.
>>
>> Let's try a few things, just to see why you're getting stuck.  Can you
>> write a program that reads in a file, and just prints all of its lines 
>> out
>> to screen?
>>
>>
> ___
> 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] Help with file I/O.

2005-07-31 Thread Nathan Pinno
Here's the improved version.
file = raw_input("File name please: ")
f = open(file)
for line in f.readlines():
print line
f.close()

- Original Message - 
From: "Nathan Pinno" <[EMAIL PROTECTED]>
To: "Danny Yoo" <[EMAIL PROTECTED]>
Cc: 
Sent: Sunday, July 31, 2005 2:29 PM
Subject: Re: [Tutor] Help with file I/O.


> Here's my work. I call it filewriter.
> The code:
> file = raw_input("File name please: ")
> f = file(file, "r")
> for line in f.readlines():
>print line
> f.close()
>
> Will it do the trick?
>
> Nathan
> - Original Message - 
> From: "Danny Yoo" <[EMAIL PROTECTED]>
> To: "Nathan Pinno" <[EMAIL PROTECTED]>
> Cc: 
> Sent: Sunday, July 31, 2005 12:22 AM
> Subject: Re: [Tutor] Help with file I/O.
>
>
>>
>>
>> On Sun, 31 Jul 2005, Nathan Pinno wrote:
>>
>>> Well, you saw my password program. That was my first attempt at using
>>> file I/O. Thought I'd try it big time. You saw where that went.
>>
>> Ok, let's take a look.  It was from this message, right?
>>
>>http://mail.python.org/pipermail/tutor/2005-July/039478.html
>>
>> That was such a while back that I think you probably learned a lot since
>> then, and I think a few of the issues there were less about I/O and more
>> about just general programming.
>>
>> Let's try a few things, just to see why you're getting stuck.  Can you
>> write a program that reads in a file, and just prints all of its lines 
>> out
>> to screen?
>>
>>
> ___
> 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] Help with file I/O.

2005-07-31 Thread Nathan Pinno
Okay I understand how to open and read to a file, but how do I write to a 
file, e.g. a list.
- Original Message - 
From: "Nathan Pinno" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>; "Danny Yoo" 
<[EMAIL PROTECTED]>
Cc: 
Sent: Sunday, July 31, 2005 2:46 PM
Subject: Re: [Tutor] Help with file I/O.


> Here's the improved version.
> file = raw_input("File name please: ")
> f = open(file)
> for line in f.readlines():
>print line
> f.close()
>
> - Original Message - 
> From: "Nathan Pinno" <[EMAIL PROTECTED]>
> To: "Danny Yoo" <[EMAIL PROTECTED]>
> Cc: 
> Sent: Sunday, July 31, 2005 2:29 PM
> Subject: Re: [Tutor] Help with file I/O.
>
>
>> Here's my work. I call it filewriter.
>> The code:
>> file = raw_input("File name please: ")
>> f = file(file, "r")
>> for line in f.readlines():
>>print line
>> f.close()
>>
>> Will it do the trick?
>>
>> Nathan
>> - Original Message - 
>> From: "Danny Yoo" <[EMAIL PROTECTED]>
>> To: "Nathan Pinno" <[EMAIL PROTECTED]>
>> Cc: 
>> Sent: Sunday, July 31, 2005 12:22 AM
>> Subject: Re: [Tutor] Help with file I/O.
>>
>>
>>>
>>>
>>> On Sun, 31 Jul 2005, Nathan Pinno wrote:
>>>
>>>> Well, you saw my password program. That was my first attempt at using
>>>> file I/O. Thought I'd try it big time. You saw where that went.
>>>
>>> Ok, let's take a look.  It was from this message, right?
>>>
>>>http://mail.python.org/pipermail/tutor/2005-July/039478.html
>>>
>>> That was such a while back that I think you probably learned a lot since
>>> then, and I think a few of the issues there were less about I/O and more
>>> about just general programming.
>>>
>>> Let's try a few things, just to see why you're getting stuck.  Can you
>>> write a program that reads in a file, and just prints all of its lines 
>>> out
>>> to screen?
>>>
>>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Thanks to all!

2005-07-31 Thread Nathan Pinno



Thank you to all. All my calculators run perfect. I can now make a perfect 
Giant Calculator as well.
 
Thanks again,
Nathan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Thanks to all!

2005-07-31 Thread Nathan Pinno



The Giant Calculator is perfect also!

  - Original Message - 
  From: 
  Nathan 
  Pinno 
  To: tutor@python.org 
  Sent: Sunday, July 31, 2005 3:34 PM
  Subject: [Tutor] Thanks to all!
  
  Thank you to all. All my calculators run perfect. I can now make a 
  perfect Giant Calculator as well.
   
  Thanks again,
  Nathan
  
  

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


Re: [Tutor] Help with file I/O.

2005-07-31 Thread Nathan Pinno
I fixed it. Here is the latest code:
filename = raw_input("File name please: ")
f = file(filename, "r")
for line in f.readlines():
print line
f.close()

Thanks for taking the time to explain the writing part, that was really 
baffling me. Now I'm first going to write the main part of a password 
program, then when that's solid, I'll add the file I/O. Maybe I'll try the 
exercise where I have to add file I/O to a grades program, in the 
Non-Programmer's Tutorial for Python.
- Original Message - 
From: "luke" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>; "Danny Yoo" 
<[EMAIL PROTECTED]>
Cc: 
Sent: Sunday, July 31, 2005 4:04 PM
Subject: Re: [Tutor] Help with file I/O.


> Nathan,
>
> I saw in your previous example that you called
> #quote
> file = raw_input("File name please: ")
> f = file(file, "r")
> for line in f.readlines():
>print line
> f.close()
> #endquote
>
> the reason you were getting an error is that
> you made a variable named "file" on line one,
> which then overwrote the builtin method
> "file" in your namespace.
> therefore, the compiler throws a
> "string not callable error"
> because it's trying to call "File name please: "(file, "r")
> which of course doesn't work.
>
> What you want to do is make __sure__
> that you never name a variable the same thing as a function
> unless you're sure that's what you want to do.
> I believe some poeple recommend that you use
> nouns for variables (because they're things)
> and verbs for functions (because it's an action)
> but in this case,
> just make sure not to use "file"
> or "open" or "str" or "int" or anything as variable names.
>
> as for your other question,
>
>> Okay I understand how to open and read to a file, but how do I write to a
>> file, e.g. a list.
>
> you should really read the tutorial and try to figure it out before asking
> us.
> I am going to give you the answer but don't keep reading if you want to
> figure it out yourself.
>
> def WriteToFile(listoflines,filename="default.txt"):
>  f = file(filename, "w")
>  f.writelines(listoflines)
>  f.close()
>
> def main(args):
>  text = ["hello\r\n","Good Morning nathan.\r\n"]
>  filename = ""
>  for arg in args:
>if arg == "-f" or arg == "--filename":
>  grab_next_arg = 1
>  continue
>if grab_next_arg:
>  filename = arg
>  break
>
>  if filename != "":
>WriteToFile(text,filename)
>  else:
>WriteToFile(text)
>
> hope that helps.
> -Luke
>
>> - Original Message -
>> From: "Nathan Pinno" <[EMAIL PROTECTED]>
>> To: "Nathan Pinno" <[EMAIL PROTECTED]>; "Danny Yoo"
>> <[EMAIL PROTECTED]>
>> Cc: 
>> Sent: Sunday, July 31, 2005 2:46 PM
>> Subject: Re: [Tutor] Help with file I/O.
>>
>>
>> > Here's the improved version.
>> > file = raw_input("File name please: ")
>> > f = open(file)
>> > for line in f.readlines():
>> >print line
>> > f.close()
>> >
>> > - Original Message -
>> > From: "Nathan Pinno" <[EMAIL PROTECTED]>
>> > To: "Danny Yoo" <[EMAIL PROTECTED]>
>> > Cc: 
>> > Sent: Sunday, July 31, 2005 2:29 PM
>> > Subject: Re: [Tutor] Help with file I/O.
>> >
>> >
>> >> Here's my work. I call it filewriter.
>> >> The code:
>> >> file = raw_input("File name please: ")
>> >> f = file(file, "r")
>> >> for line in f.readlines():
>> >>print line
>> >> f.close()
>> >>
>> >> Will it do the trick?
>> >>
>> >> Nathan
>> >> - Original Message -
>> >> From: "Danny Yoo" <[EMAIL PROTECTED]>
>> >> To: "Nathan Pinno" <[EMAIL PROTECTED]>
>> >> Cc: 
>> >> Sent: Sunday, July 31, 2005 12:22 AM
>> >> Subject: Re: [Tutor] Help with file I/O.
>> >>
>> >>
>> >>>
>> >>>
>> >>> On Sun, 31 Jul 2005, Nathan Pinno wrote:
>> >>>
>> >>>> Well, you saw my password program. That was my first attempt at 
>> >>>> using
>> >>>> file I/O. Thought I'd try it big time. You saw where that went.
>> >>>
>> >>> Ok, let's take a look.  It was from this message, right?
>> >>>
>> >>>http://mail.python.org/pipermail/tutor/2005-July/039478.html
>> >>>
>> >>> That was such a while back that I think you probably learned a lot
> since
>> >>> then, and I think a few of the issues there were less about I/O and
> more
>> >>> about just general programming.
>> >>>
>> >>> Let's try a few things, just to see why you're getting stuck.  Can 
>> >>> you
>> >>> write a program that reads in a file, and just prints all of its 
>> >>> lines
>> >>> out
>> >>> to screen?
>> >>>
>> >>>
>> >> ___
>> >> Tutor maillist  -  Tutor@python.org
>> >> http://mail.python.org/mailman/listinfo/tutor
>> >>
>> >
>> ___
>> 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] Thanks to all!

2005-07-31 Thread Nathan Pinno
I am going to try and tackle the file I/O exercise in Non-Programmers 
Tutorial For Python found at 
http://www.honors.montana.edu/~jjc/easytyt/easytut/easytut.html. Should be a 
fun task.
- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Sunday, July 31, 2005 4:32 PM
Subject: Re: [Tutor] Thanks to all!


>
> Congratulations!  So what are you going to try next?
>
> --Todd
>
> On Sunday 31 July 2005 06:27 pm, Nathan Pinno wrote:
>> The Giant Calculator is perfect also!
>>   - Original Message -
>>   From: Nathan Pinno
>>   To: tutor@python.org
>>   Sent: Sunday, July 31, 2005 3:34 PM
>>   Subject: [Tutor] Thanks to all!
>>
>>
>>   Thank you to all. All my calculators run perfect. I can now make a
>> perfect Giant Calculator as well.
>>
>>   Thanks again,
>>   Nathan
>>
>>
>> ---
>>---
>>
>>
>>   ___
>>   Tutor maillist  -  Tutor@python.org
>>   http://mail.python.org/mailman/listinfo/tutor
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What's the invaild syntax? Error message and relative code supplied.

2005-07-31 Thread Nathan Pinno



What the invalid syntax? Here is the error message:
SyntaxError: invalid syntax  File "D:/Python22/grades.py", line 
66    which = 
which-1    ^SyntaxError: invalid 
syntax
 
Here is the code:
 
max_points = [25,25,50,25,100]assignments = ['hw ch 1','hw ch 
2','quiz   ','hw ch 3','test']students = {'#Max':max_points}
 
def print_menu():    print "1. Add 
student"    print "2. Remove student"    
print "3. Print grades"    print "4. Record 
grade"    print "9. Exit"
 
def print_all_grades():    print 
'\t',    for i in 
range(len(assignments)):    print 
assignments[1],'\t',    print    keys = 
students.keys()    keys.sort()    for x in 
keys:    print 
x,'\t',    grades = 
students[x]    
print_grades(grades)
 
def print_grades(grades):    for i in 
range(len(grades)):    print 
grades[i],'\t\t',    print
 
def choice():    return int(raw_input("Menu Choice: 
"))
 
def school():    return raw_input("Student: ")
 
while 1:    print_menu()    
menu_choice = choice()    if menu_choice == 
1:    print "Add 
student"    name = 
school()    students[name] = 
[0]*len(max_points)    elif menu_choice == 
2:    print "Remove 
student"    name = 
school()    if 
students.has_key(name):    
del students[name]    
else:    
print "Student: ",name," not found."    elif menu_choice == 
3:    print_all_grades()
 
    elif menu_choice == 
4:    print "Record 
Grade"    name = 
school()    if 
students.has_key(name):    
grades = 
students[name]    
print "Type in the number of the grade to 
record"    
print "Type in a 0 (zero) to 
exit"    for 
i in 
range(len(assignments)):    
print i+1,' 
',assignments[i],'\t',    
print    
print_grades(grades)    
which = 
1234    while 
which != 
-1:    
which = int(raw_input("Change which Grade: 
")    
which = 
which-1    
if 0 <= which < 
len(grades):    
grade = int(raw_input("Grade: 
")    
grades[which] = 
grade    
elif which != 
-1:    
print "Invalid Grade 
Number"    
else:    
print "Student not found"    elif menu_choice == 
9:    break    
else:    print "That's not a 
choice!"print "Goodbye."
Thanks for the help in advance!
Nathan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What's the invaild syntax? Error message and relativecode supplied.

2005-07-31 Thread Nathan Pinno
Thanks Todd. Another one saved by you.
- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Sunday, July 31, 2005 5:56 PM
Subject: Re: [Tutor] What's the invaild syntax? Error message and 
relativecode supplied.


>
> Remember this problem from yesterday?
>
> Take a look at the line before the one you are getting the error on.
> And count the ('s and the )'s.
>
> --Todd
>
>
>
> On Sunday 31 July 2005 07:38 pm, Nathan Pinno wrote:
>> What the invalid syntax? Here is the error message:
>> SyntaxError: invalid syntax
>>   File "D:/Python22/grades.py", line 66
>> which = which-1
>> ^
>> SyntaxError: invalid syntax
>>
>> Here is the code:
>>
>> max_points = [25,25,50,25,100]
>> assignments = ['hw ch 1','hw ch 2','quiz   ','hw ch 3','test']
>> students = {'#Max':max_points}
>>
>> def print_menu():
>> print "1. Add student"
>> print "2. Remove student"
>> print "3. Print grades"
>> print "4. Record grade"
>> print "9. Exit"
>>
>> def print_all_grades():
>> print '\t',
>> for i in range(len(assignments)):
>> print assignments[1],'\t',
>> print
>> keys = students.keys()
>> keys.sort()
>> for x in keys:
>> print x,'\t',
>> grades = students[x]
>> print_grades(grades)
>>
>> def print_grades(grades):
>> for i in range(len(grades)):
>> print grades[i],'\t\t',
>> print
>>
>> def choice():
>> return int(raw_input("Menu Choice: "))
>>
>> def school():
>> return raw_input("Student: ")
>>
>> while 1:
>> print_menu()
>> menu_choice = choice()
>> if menu_choice == 1:
>> print "Add student"
>> name = school()
>> students[name] = [0]*len(max_points)
>> elif menu_choice == 2:
>> print "Remove student"
>> name = school()
>> if students.has_key(name):
>> del students[name]
>> else:
>> print "Student: ",name," not found."
>> elif menu_choice == 3:
>> print_all_grades()
>>
>> elif menu_choice == 4:
>> print "Record Grade"
>> name = school()
>> if students.has_key(name):
>> grades = students[name]
>> print "Type in the number of the grade to record"
>> print "Type in a 0 (zero) to exit"
>> for i in range(len(assignments)):
>> print i+1,' ',assignments[i],'\t',
>> print
>> print_grades(grades)
>> which = 1234
>> while which != -1:
>> which = int(raw_input("Change which Grade: ")
>> which = which-1
>> if 0 <= which < len(grades):
>> grade = int(raw_input("Grade: ")
>> grades[which] = grade
>> elif which != -1:
>> print "Invalid Grade Number"
>> else:
>> print "Student not found"
>> elif menu_choice == 9:
>> break
>> else:
>> print "That's not a choice!"
>> print "Goodbye."
>>
>> Thanks for the help in advance!
>> Nathan
>





> ___
> 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] What's the invaild syntax? Error message and relative codesupplied.

2005-07-31 Thread Nathan Pinno
Thanks again Luke.
- Original Message - 
From: "luke" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>; 
Sent: Sunday, July 31, 2005 5:50 PM
Subject: Re: [Tutor] What's the invaild syntax? Error message and relative 
codesupplied.


> NATHAN!
> you have had this exact same problem yesterday!
> cmon man.
> If you see an invalid syntax error,
> look on the preceeding line.
> it's usually caused by not enough parenthesis for your function call.
> so we scroll down to lines 64-66...
>
>>which = 1234
>>while which != -1:
>>which = int(raw_input("Change which Grade: ")
> tada there's our error.
> you forgot an extra parenthesis.
> however many (( you have on a line you need ot have the same number of )) 
> on
> the line.
> which = int(raw_input("Change which Grade: ")
> becomes
> which = int(raw_input("Change which Grade: "))
>
> HTH,
> -Luke
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with file I/O.

2005-07-31 Thread Nathan Pinno
Does it display stars instead?
- Original Message - 
From: "Alan G" <[EMAIL PROTECTED]>
To: "Nathan Pinno" <[EMAIL PROTECTED]>; "Alberto Troiano" 
<[EMAIL PROTECTED]>; "Danny Yoo" <[EMAIL PROTECTED]>; "luke" 
<[EMAIL PROTECTED]>
Cc: 
Sent: Sunday, July 31, 2005 5:45 PM
Subject: Re: [Tutor] Help with file I/O.


>> baffling me. Now I'm first going to write the main part of a password
>
> You might find the getpass module useful for that...
> It provides a raw_input style prompt that doesn't
> display what the user types...
>
> HTH,
>
> Alan G.
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


  1   2   3   4   >