[Tutor] role playing game - help needed

2010-12-05 Thread Alan Stern
Hi all.  My name is Al Stern.  I am an absolute beginner to programming and 
based on what I'd read, decided to try Python as my 1st language.  I am 
starting with a book called Python Programming for the Absolute Beginner by 
Michael Dawson.  The book has been pretty good and up to this point, I have 
grasped all the concepts it has covered.  At the end of each chapter, there are 
a number of challenges you need to complete before moving on.  Problem is, I 
have gotten stumped on one in Chapter 5: Lists and Dictionaries.

I'm not sure exactly how this mailing list works but was hoping someone here 
could give me some insight as to how to proceed.  Apologies if I am not posting 
the following in the correct format.  I just copied and pasted.)  Feel free to 
point me in the right direction if there are instructions as to how to do it.

Here is the challenge: Write a Character Creator program for a role-playing 
game. The player should be given a pool of 30 points to spend on four 
attributes: Strength, Health, Wisdom, and Dexterity. The >player should be able 
to spend points from the pool on any attribute and should also be able to take 
points from an attribute and put them back into the pool.

I think I did ok setting up the variables but haven't figured out where to go 
from there.

Here is what I have (along with my latest error message).  Thanks in advance.

# character creator / role playing game
# have 30 total points to work with

# set variables

attributes = ["strength", "health", "wisdom", "dexterity"]
points = [0,0,0,0]
MAX_POINTS = 30
available_points = MAX_POINTS - sum(points)

print("""
Our hero will need strength, health, wisdom and dexterity to survive.
You will have a limited amount of points to 'spend' on these attributes.
Use them wisely.  His life depends on it.
"""
)

# point allocation

print ("You have", available_points, "points available to use.")

for x in range(len(attributes)):
  print ("\t",attributes[x], points[x])

for x in range(len(attributes)):
point_choice = input("\n\nHow many points do you want to assign to " +  
attributes[x]  + "?: ")


__
Alan Stern

Rising Realty
1820 W. Webster Ave #307
Chicago, IL 60614

(W)773-395-
(F)773-395-9553
(C)773-502-2556

www.risingrealty.com
Statement of Confidentiality
The contents of this e-mail message and its attachments are intended solely for 
the addressee(s) hereof. In addition, this e-mail transmission may be 
confidential and it may be subject to privilege protecting communications 
between attorneys or solicitors and their clients. If you are not the named 
addressee, or if this message has been addressed to you in error, you are 
directed not to read, disclose, reproduce, distribute, disseminate or otherwise 
use this transmission. Delivery of this message to any person other than the 
intended recipient(s) is not intended in any way to waive privilege or 
confidentiality.  If you have received this transmission in error, please alert 
the sender by reply e-mail; we also request that you immediately delete this 
message and its attachments, if any. Rising Realty reserve the right to monitor 
all e-mail communications through their networks.


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


[Tutor] Tkinter Scale Question

2010-12-05 Thread Sean Finnegan
Hi Everyone,

I have successfully visualized 4 layers in Tkinter and am now trying to
apply some sort of zoom in/out and pan function so that the layers can be
seen more closely. I am using a package to visualize the map layers where i
have separate py files for points, polylines, polygons, map, layers,
readshapefile, feature, and features, and a main file that tells tkinter
what to draw based on the bounding box settings in the map file. I am not
exactly sure what path I should be exploring, either a button module or a
scale module. I have successfully visualized both, but can not seem to make
them take on the functionality that I need.

Most recently I am trying some bind code in the main file that I have
modified to try and fit the map needs, but it isn't producing the desired
functionality either. Can someone please give me some direction as to which
way would be best to approach this?


from Tkinter import *
from Map import *
root = Tk()

import sys
if sys.version_info < (3,):
import Tkinter as tk
import tkSimpleDialog as tk_dialog
else:
import tkinter as tk
from tkinter import simpledialog as tk_dialog

class Viewer(object):
#Base class viewer to display map

def __init__(self, parent, width=800, height=600,
 min_x=-2.5, min_y=-1.5, max_x=1.):

self.parent = parent
self.canvas_width = width
self.canvas_height = height

# The following are drawing boundaries in the complex plane
self.min_x = min_x
self.min_y = min_y
self.max_x = max_x
self.calculate_pixel_size()
self.max_y = self.min_y + self.canvas_height*self.pixel_size

self.calculating = False
self.nb_iterations = 20
self.normal_zoom(None)

self.canvas = tk.Canvas(parent, width=width, height=height)
self.canvas.pack()
self.status = tk.Label(self.parent, text="", bd=1, relief=tk.SUNKEN,
   anchor=tk.W)
self.status.pack(side=tk.BOTTOM, fill=tk.X)
self.status2 = tk.Label(self.parent, text=self.info(), bd=1,
relief=tk.SUNKEN, anchor=tk.W)
self.status2.pack(side=tk.BOTTOM, fill=tk.X)

# We change the size of the image using the keyboard.
self.parent.bind("+", self.zoom_in)
self.parent.bind("-", self.zoom_out)
self.parent.bind("n", self.normal_zoom)
self.parent.bind("b", self.bigger_zoom)

# Set the maximum number of iterations via a keyboard-triggered
event
self.parent.bind("i", self.set_max_iter)

# We move the canvas using the mouse.
self.translation_line = None
self.parent.bind("", self.mouse_down)
self.parent.bind("", self.mouse_motion)
self.parent.bind("", self.mouse_up)

self.draw_map()  # Needs to be implemented by subclass

def info(self):
#information about map location'''
return "Location: (%f, %f) to (%f, %f)" %(self.min_x, self.min_y,
  self.max_x, self.max_y)

def calculate_pixel_size(self):
#Calculates the size of a (square) pixel in complex plane
#coordinates based on the canvas_width.
self.pixel_size = 1.*(self.max_x - self.min_x)/self.canvas_width
return

def mouse_down(self, event):
#records the x and y positions of the mouse when the left button
   #is clicked.
self.start_x = self.canvas.canvasx(event.x)
self.start_y = self.canvas.canvasy(event.y)

def mouse_motion(self, event):
#keep track of the mouse motion by drawing a line from its
   #starting point to the current point.
x = self.canvas.canvasx(event.x)
y = self.canvas.canvasy(event.y)

if (self.start_x != event.x)  and (self.start_y != event.y) :
self.canvas.delete(self.translation_line)
self.translation_line = self.canvas.create_line(
self.start_x, self.start_y, x, y,
fill="orange")
self.canvas.update_idletasks()

def mouse_up(self, event):
#Moves the canvas based on the mouse motion
dx = (self.start_x - event.x)*self.pixel_size
dy = (self.start_y - event.y)*self.pixel_size
self.min_x += dx
self.max_x += dx
# y-coordinate in complex plane run in opposite direction from
# screen coordinates
self.min_y -= dy
self.max_y -= dy
self.canvas.delete(self.translation_line)
self.status.config(text="Moving the map.  Please wait.")
self.status.update_idletasks()
self.status2.config(text=self.info())
self.status2.update_idletasks()
self.draw_map()

def normal_zoom(self, event, scale=1):
#Sets the zooming in/out scale to its normal value
if scale==1:
self.zoom_info = "[normal zoom]"
else:
self.zoom_info = "[faster zoom]"
   

Re: [Tutor] Which non SQL Database ?

2010-12-05 Thread Alan Gauld


"Knacktus"  wrote


Why not use SQL?
SQLlite comes with Python, is small, easy to use and if necessary 
can be

used in-memory and as such fast.
The NoSQL databases seem to be en vogue. Some big internet companies 
have started to use them, like Google with its Big Table.


There are cases where it makes sense but they are nearly all cases 
where
extreme performance is required for a small fixed set of queries. In 
these

cases the data structures can be optimised to match the queries and
low level file access can provide optimum access speed. But unless you
absolutely know you need that a lightweight SQL database like SQLlite
or firebird will be easier to configure, easier to query and be much 
more
scaleable and flexible. (Plus you get for free the ability to run 
ad-hoc

MIS style reports of the back of the SQL engine.)

one kind of the database type is the clear winner, but most use 
cases can be modelled with both.


Yes, its like OOP v procedural, both can be used for any problem but
usually OOP is is the more powerful, flexibly and easier option. But
for specific, small or high performance apps procedural can be better.

My conclusion and what draw me finally to MongoDB over PostgreSQL 
and SQLAlqemy was:


I've no idea what MongoDB is like but PostGrres is one of the more 
complex
(and powerful) SQL options. Certainly not my first chooice for a 
small,

single user app.

1) Really the ease of use (from setting up the database and later 
when it comes to administration and scaling, which is particularly 
easy).


Most SQL databases come with GUI tools for all of that.


MongoDB is very useful for prototyping.

2) I don't need complex transactions and the ability to perform 
complex, not in advanced known queries.


Fixed in advance, simple, single dimensional queries are the area
where non SQL can be a valid choice. Any kind of multi dimensional
query will quickly become difficult to code and maintain, and thats
where SQL wins. In my experience the majority of so-called
"simple database" applications very quickly become complicated!

Of course if all you need is data persistence then flat files are
a perfectly valid option. But I'm assuming here that database
implies off-disk data search and access.


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] Which non SQL Database ?

2010-12-05 Thread Knacktus

Am 05.12.2010 10:41, schrieb Alan Gauld:


"Jorge Biquez"  wrote


Talking with a friend about what he will do (he use C only) he suggest
to take a look on dBase format file since it is a stable


True enough and Dabo is worth a look since it provides not only a dbase
format db engine but a good GUI builder tool too.

However


(Berkley) database file format (I hope I understood this one
correctly) . Plain files it is not an option since I would like to
have option to do rapid searches.


Why not use SQL?
SQLlite comes with Python, is small, easy to use and if necessary can be
used in-memory and as such fast.
Once you have decided to go down the database route then not using SQL
nowadays is a very odd decision. Its rather liike going out looking for
a car that has solid types instead of pneumatics. Why would you want to?
The NoSQL databases seem to be en vogue. Some big internet companies 
have started to use them, like Google with its Big Table. That's how I 
stumbled across them. There're a lot of discussions going on on the 
internet which is better for which use case. There're some cases where 
one kind of the database type is the clear winner, but most use cases 
can be modelled with both.


My conclusion and what draw me finally to MongoDB over PostgreSQL and 
SQLAlqemy was:


1) Really the ease of use (from setting up the database and later when 
it comes to administration and scaling, which is particularly easy). 
MongoDB is very useful for prototyping.


2) I don't need complex transactions and the ability to perform complex, 
not in advanced known queries.


I'd say SQL-DBs are more sophisticated but more complex to use. For the 
sake of learning, go with SQL. It doesn't hurt having a driver license. 
If you need to go to the bakery around the corner the driver license 
doesn't prevent you to jump on your bicycle.


Cheers,

Jan



HTH,



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


Re: [Tutor] Which non SQL Database ?

2010-12-05 Thread Alan Gauld


"Jorge Biquez"  wrote

Talking with a friend about what he will do (he use C only) he 
suggest to take a look on dBase format file since it is a stable 


True enough and Dabo is worth a look since it provides not only 
a dbase format db engine but a good GUI builder tool too.


However

(Berkley) database file format (I hope I understood this one 
correctly) . Plain files it is not an option since I would like to 
have option to do rapid searches.


Why not use SQL?
SQLlite comes with Python, is small, easy to use and if necessary 
can be used in-memory and as such fast. 

Once you have decided to go down the database route then not 
using SQL nowadays is a very odd decision. Its rather liike 
going out looking for a car that has solid types instead of 
pneumatics. Why would you want to?


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] printing in python 3.x

2010-12-05 Thread Alan Gauld


"Monte Milanuk"  wrote

... I was under the impression that controlling exactly layout via 
html was kind of difficult and somewhat fragile.


Absolutely true, especially compared to PDF. But its much
better than it was say 10-15 years ago. But if you can construct
the page such that precision layout is not required that isn't
too big a problem.

perhaps less so as one could make some fairly concrete assumptions 
about the paper size being used in this situation.  Is it common to 
use HTML for formatting printed reports?!?  Could you give an 
example of how you'd control the layout of specific fields on a 
printed report?


Its not unknown. It depends on how precise it needs to be.
But if you use tables extensively, with fixed widths etc you can
get fairly good control. Also use CSS stylesheets to control fonts 
etc.

HTML for printing is almost the opposite of HTML for browser display
- you avoid all the flexible size settings etc and use fixed sixes and 
fonts.


The great thing about HTML is that you can very quickly
try things out manually before committing the effort of generating
it by code. If you are in control of the printed output then you 
should

be able to get precision good enough. If not then PDF may be your
best bet. One option is to get the HTML working well then print
to a PDF printer file. Then you can ship the PDF file with its
precise layout but retain the ease of production of the HTML.

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] Which non SQL Database ?

2010-12-05 Thread Knacktus

Am 04.12.2010 23:42, schrieb Jorge Biquez:

Hello all.

Newbie question. Sorry.

As part of my process to learn python I am working on two personal
applications. Both will do it fine with a simple structure of data
stored in files. I now there are lot of databases around I can use but I
would like to know yoor advice on what other options you would consider
for the job (it is training so no pressure on performance). One
application will run as a desktop one,under Windows, Linux, Macintosh,
being able to update data, not much, not complex, not many records. The
second application, running behind web pages, will do the same, I mean,
process simple data, updating showing data. not much info, not complex.
As an excersice it is more than enough I guess and will let me learn
what I need for now.
Talking with a friend about what he will do (he use C only) he suggest
to take a look on dBase format file since it is a stable format, fast
and the index structure will be fine or maybe go with BD (Berkley)
database file format (I hope I understood this one correctly) . Plain
files it is not an option since I would like to have option to do rapid
searches.

What would do you suggest to take a look? If possible available under
the 3 plattforms.
As a non SQL Database I can recommend MongoDB. It's a document store, 
which uses binary json as format. You can create secondary indexes and 
also perform more sophisticated queris.
The main advantage from my point of view is the ease of use. 
Installation was a breeze and it has an easy to use python driver. Note 
that you need a 64-bit OS to use it with bigger data volumes (I remember 
> 3 GB, but it's all on their website).





Thanks in advance for your comments.

Jorge Biquez

___
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