Re: [Tutor] design question (Django?)

2013-04-14 Thread Albert-Jan Roskam


 > Subject: Re: [Tutor] design question (Django?)
> 
> On 13/04/13 09:48, Albert-Jan Roskam wrote:
> 
>>  I think I have to make a diagram of this. This stuff is quite hard
> 
> You could use a simple UML class diagram (class -> table). See the OOP topic 
> in my V3 tutorial for simple examples.
> 
> Or you could use a proper entity relationship diagram(ERD) - see wikipedia 
> for 
> details and examples (there are various notational variations)
> 
> They all show the same concepts. UML will be best if you plan
> on using OOP in the python code. ERD is better for vanilla database design.

Hi Alan, I am reading it now. Thanks for the suggestion. I have to read more 
about Django to decide whether this is the way to do it. First impression: yes. 
The database abstraction API also implies that I should use OOP. Step #1: 
defining the model ;-) https://docs.djangoproject.com/en/dev/topics/db/models/
Would it also be a good idea to simultaneously make a paper-and-pencil drawing 
of the UI? It seems like a good way to figure out what I really want. For me, 
the hardest part of software construction is the design stage.

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


Re: [Tutor] design question (Django?)

2013-04-14 Thread Don Jennings

On Apr 14, 2013, at 7:06 AM, Albert-Jan Roskam wrote:

> 
> 
>  > Subject: Re: [Tutor] design question (Django?)
>> 
>> On 13/04/13 09:48, Albert-Jan Roskam wrote:
>> 
>>> I think I have to make a diagram of this. This stuff is quite hard
>> 
>> You could use a simple UML class diagram (class -> table). See the OOP topic 
>> in my V3 tutorial for simple examples.
>> 
>> Or you could use a proper entity relationship diagram(ERD) - see wikipedia 
>> for 
>> details and examples (there are various notational variations)
>> 
>> They all show the same concepts. UML will be best if you plan
>> on using OOP in the python code. ERD is better for vanilla database design.
> 
> Hi Alan, I am reading it now. Thanks for the suggestion. I have to read more 
> about Django to decide whether this is the way to do it. First impression: 
> yes. The database abstraction API also implies that I should use OOP. Step 
> #1: defining the model ;-) 
> https://docs.djangoproject.com/en/dev/topics/db/models/
> Would it also be a good idea to simultaneously make a paper-and-pencil 
> drawing of the UI?

Absolutely! Test it with three users. See Jakob Nielsen's brief take on the 
matter:

http://www.nngroup.com/articles/paper-prototyping/

Take care,
Don

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


Re: [Tutor] design question (Django?)

2013-04-14 Thread ALAN GAULD

>Would it also be a good idea to simultaneously make a paper-and-pencil drawing 
>of the UI? Personally I do. At work we call these UI sketches  "wireframes" 
>and they are used to figure 
out the interaction. The focus is on the relative position of controls and the 
workflow for 
the user rather than the cosmetics. There are lots of articles and web sites on 
the science 
of UI design and usability.
the hardest part of software construction is the design stage.It always is and 
the bigger the project the more formal the design needs to be.
Most of the projects discussed on the tutor list can be done with little or no 
design 
(the equivalent of building a dog kennel or garden shed) but as you progress to 
more complex designs (think house extension) you need at least a basic design 
diagram to follow. And as you move into big projects with multiple developers 
or even multiple teams (think skyscraper or airport terminal) you really need 
clear, formally expressed designs to keep everything consistent. One of the 
things 
I like about UML is that it can be used at all levels, just pick the bits that 
are 
relevant to your project.

HTH,

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


Re: [Tutor] creating dictionary from a list

2013-04-14 Thread Saad Javed
Steven,

You're right about Mark's email. I didn't get the humor and thought the
remark was kinda tough on me. You correctly pointed out his intent. So my
apologies to Mark.

As for the underscores, what happened is that *I didn't voluntarily add the
underscores to begin with. *If you read the emails again, after Mark's
answer about not looping, I asked that the dictionary created as a result
of his code wasn't ordered. In reply, he sent me a portion of his previous
email containing underscores before Wed (__Wed)! I thought it was the
strange but since I'm a beginner, I copied the code and applied it which of
course threw up a syntax error. What I wanted to ask Mark was that *why* had
*he* added underscores because they were throwing up errors for me. He kept
pointing me to his earlier email and asking me compare my line with his
line and I'll find out what the problem is.

In my mind, I thought I was not entering the underscores correctly or at
the right position. As you have explained it turns out it was the email
client which was adding stuff on its own. It added the underscores to
Mark's first response to my dictionary order question and I took it as *Mark's
answer.*

Regards,

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


Re: [Tutor] FYI: An Introduction to Interactive Programming in Python

2013-04-14 Thread David Kemeza
I'd really be interested in see that code since.  I'm learning python right
now and looking at code helps with my learning process.

Thanx
-dave


On Tue, Apr 9, 2013 at 11:32 AM, brian arb  wrote:

> One game  wrote along time ago when I was first learning Python and App
> Engine is http://cdacabeecdebcabab.appspot.com/
> It's kind of a  non-interactive Sudoku puzzle, the only really
> interaction is to click "solve this" or "display next puzzle" then to watch
> the python code written attempt to solve the puzzle you click on the button
> "next iteration" until you reach a solution or the code fails to resolve
> any more of the cells.
>
>
>
>
> On Mon, Apr 8, 2013 at 7:58 PM, Steven D'Aprano wrote:
>
>> On 09/04/13 06:38, brian arb wrote:
>>
>>> An Introduction to Interactive Programming in PythonJoe Warren, Scott
>>>
>>> Rixner, Stephen Wong and John Greiner
>>>
>>> This course is designed to be a fun introduction to the basics of
>>> programming in Python. Our main focus will be on building simple
>>> interactive games such as Pong, Blackjack and Asteroids.
>>>
>>> https://www.coursera.org/**course/interactivepython
>>>
>>
>> Thanks for the link Brian.
>>
>> As an aside, I wonder, apart from Conway's Game of Life, which isn't
>> actually a game at all, what's a non-interactive game?
>>
>>
>>
>> --
>> 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 maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Issue With a Python Game

2013-04-14 Thread John Bochicchio
I have a question about a game I am making. I finished the overall code,
but keep getting errors when I try to play. This is my most common error:
C:\Users\John\Documents\Python Games\Noah>python nickeladventuredemo.py
Traceback (most recent call last):
  File "nickeladventuredemo.py", line 451, in 
main()
  File "nickeladventuredemo.py", line 78, in main
levels = readLevelsFile('levels.txt')
  File "nickeladventuredemo.py", line 371, in readLevelsFile
assert startx != None  and starty!= None, 'Level %s (around line %s) in
%s i
s missing a "@" or "+" to mark the start point.' % (levelNum+1, lineNum,
filenam
e)
AssertionError: Level 1 (around line 10) in levels.txt is missing a "@" or
"+" t
o mark the start point.

The error has something to do with the levels. I will attach the code and
levels, as they are fairly long.

-- 
A computer without a Microsoft operating system is like a dog without
bricks tied to its head.
; Starting demo level:
 
##  #
#   .   #
#   $   #
# .$@$. #
$   #
   #.   #
   #   ##
   #

; 1

   ###
  ## # 
 ##  ###  #
## $  #
#   @$ #  #
### $###  #
  #  #..  #
 ## ##.# ##
 #  ##
 # ##
 ###

; 2

 ## #
## ## . #
# ## $. #
 ## $   #
## $@ ###
# $  ##
#.. ## ##
#   # ##
# #

; 3

   #
  ##   #
  ##
  # $ ##
#  $ $#
# $ $ #
   ## ## $ $ $#
   #  .#  $ $ #
   #  .#  #
# #
# @  #
##
##  ##
 

; 4

  ###
 ## #  @#
### $ $$#   #
# ##$$$ #
#  #  $ #   #
## ##
#.. ..$ #*##
# ..###
#  ..#
#

; 5

  ###
 #####
### $ $#$ $ ###
# #$ $ # $ $# #
# $  ..#..  $ #
#  $...#...$  #
# $ .. * .. $ #
## @ ##
# $ ..   .. $ #
#  $...#...$  #
# $  ..#..  $ #
# #$ $ # $ $# #
### $ $#$ $ ###
 #####
  ###

; 6

  ###
###.  .$.  .###
 ## $  $  $ ##
  ## ..$.. ##
   ##$#$#$##
#.$ $.#
#  @  #
### ###
   ## $ $ ##
   #.  $  .#
   ### . ###
 #

; 7

   ##
  ###
  ###  #  #  ## ###
### #   $ #
#  $ @ ...*..  $  #
# $ $  ## ###   ###
### ###   # #
 #  ###
 #   
 #

; 8

###
# ##
# ###  ##
#   #  ##
#@$***. ##$ #
#  ### .#
##  ##  # $ #
 ##  .$.#
  ###
   ##  ##


; 9

#
#. .#
#.$. .  #
## ###@ #
 #  $  ##
 # $$ ##
 #  $ #
 #  ###
 

; 10

  ##
  ##
  # @  ###
  #  #
#  ..#.#$#
# $ $ ##...  #
# .#$$   #
## ##$## #
 #  $#
  
   #  #
   #  #
 ### $#
 #  $ $   #
 # #$# 
 # #
 ###

; 11

  
###  
#   @   ##
# #. .#.###
# $$$ $$$ #
###.#.#.# #
 ##   #
    ###
 

; 12

  #
  #   #
# #   ###
#   # #   . #
# # ##  # # # # #
# $ $ $ $ $ # ##   ## $ #
# # ##.. ### $$ ###
#  ## * ## #  $$  #
##+$$   ## #  #
 #.$ $# #  
 #.##   #
 

; 13

   ###
 ### ##
 #   ###  #
 #  # #
###$#@  # #
#   # #
#   #  *. #
##$$#  *.##
 # *..#
  #...##
# #$$$ #
#   $  #
#  #


; 14

 ###
## # #
#  *.$.#
#  *.#.###
# #$@$$  #
#   ## # #
##   #
 #

; 15

   
   #@ #
  ##  #
  # .$#
  #$. #
###..$###
#  ..$  #
# $ $ # #
# # #
#   #
#

; 16

  ##
 ## #  ###
## #   # ##
# #   $.# #
##  $ $.# #
# #. ##
# $. @#
# $. 
### # #*# # ###
   .$ #
#  .$ #
## .# #
# #.$ $  ##
# #.$   # #
## #   # ##
 ###  # ##
   ##

; 17

###
   ## . . . . ###
   #  $$ $ $ $  #
   #    # #
  ##  $ # #   #
 ##  $ $ #  ### # #
##  # #    $  #
#...  # $   ###
#... @ $ ##
#... $  $ #
#  #  #
   

; 18


#  #
#  #
#$ $ $ #
#.*.*.*#
#*.*.*.#
# $ $ $#
#..#
#.*.*.*#
#$ $ $ #
# $ $ $#
#$ $ $ #
#  #
#@ #


; 19

#
#   ###
#  $  ##
## ##  ##
 # ## # 
 # # ##$   ##
 # #.   #@## $  ##
 # #.#  ##### $  ##
 # #.#  ## $  ##
 # #.#   #  ##   ## $  ##
## #.#  ##  ###   ## $  #
#  #.#   #  #*##   ##   #
#   .# # #  ##*##   #
##   #  ##
 #

; 20

 
 #  #
##$.#
#   $ $.#
# $@$...#
# $$$..##
#  $ ..#


; 21

# 
#   ### . $  #
#   $ *.. #$ ##
## $# ..* $  @#
 #  $ . ###   #
  #

; 22

   # 
   #@ .###  ###
  $$ $#
#   # . . ##  #
#  $ # . . ## #
## .  $ $$  # #
 # #  ###.  # #
 #  # #
 #   ##
 ### # 
   # .$ #
    #
 ## #
  ###

; 23

 ###
## ##
#  . ..$#$.. .  #
#  $ $  .  $ $  #
###$@$###
#  $ $  .  $ $  #
#  . ..$#$.. .  #
## ##
 ###

Re: [Tutor] How to extract a float from an instancemethod call

2013-04-14 Thread Sydney Shall



On 08/04/2013 13:52, Dave Angel wrote:

On 04/08/2013 08:40 AM, Sydney Shall wrote:

Hi,
I am  learning Python.

I use MAC OSX 10.6.8
Python 2.7.3

I have been given a project to write a program involving random walks.
I have drafted a program which has passed all the static tests, but on
testing my program i get the following error message:


Traceback (most recent call last):
   File "/Users/Sydney/Documents/6.00x Files/Problem
Sets/ProblemSet7/ps7 copy.py", line 303, in 
 testRobotMovement(StandardRobot, RectangularRoom)
   File "ps7_verify_movement.py", line 12, in testRobotMovement
   File "/Users/Sydney/Documents/6.00x Files/Problem
Sets/ProblemSet7/ps7 copy.py", line 285, in updatePositionAndClean
 while self.room.isPositionInRoom(self.position) == False:
   File "/Users/Sydney/Documents/6.00x Files/Problem
Sets/ProblemSet7/ps7 copy.py", line 163, in isPositionInRoom
 return self.room[(x,y)] in self.room
KeyError: (>, >)
 >>>

The program text referred to is the following, I give the whole module,
which is part of a larger program.
  def isPositionInRoom(self, pos):
 """
 Return True if pos is inside the room.

 pos: a Position object.
 returns: True if pos is in the room, False otherwise.
 """
 x = pos.getX
 y = pos.getY


You never show the code for Position.getX and Position.getY, but I'd 
expect they're methods that take no arguments.  in that case, you need 
parens in order to call them.


   x = pos.getX()
   y = pos.getY()


 return self.room[(x,y)] in self.room



a simple print of x and y could have revealed this as well.



Dear Dave,
Thanks for  pointing out my mistake. I thought it would be some small 
error on my part.

I had a print statement, but I could not correctly interpret the output.
It solves that problem.



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


Re: [Tutor] building a website with python

2013-04-14 Thread Brian Lamb
Without overly proselytizing any particular host you might want to check out 
Webfaction for hosting.  They have an excellent reputation for Python hosting 
and reasonable rates.   There are of course others that some may prefer, you 
can certainly google for other web hosting comparisons.

Also there are other frameworks that may be worth your time to investigate, as 
with everything it really depends what you are trying to accomplish.

Best of Luck,
Brian
On Apr 9, 2013, at 5:54 PM, Prasad, Ramit wrote:

> Benjamin Fishbein wrote:
>> 
>> Hello. I learned Python this past year (with help from many of you) and 
>> wrote many programs for my
>> small business. Now I want to build a website. I acquired the domain name 
>> through godaddy.com
>> (bookchicken.com) but have not found hosting yet.
>> I learned html, css, and javascript via codeacademy.org, but have never 
>> built a website.
>> I would like to build it with Python, and was wondering if you could give me 
>> some pointers about what
>> I need to learn first: Django is the thing to use? And do I need specific 
>> hosting to use python or are
>> all hosts basically the same.
>> Thanks,
>> Ben
> 
> http://wiki.python.org/moin/WebFrameworks
> 
> Lots of Python frameworks to choose from, though Django is the most 
> famous/popular. There are
> lighter frameworks too, depending on what you need.
> 
> Your hosting solution to support Python, and I do not believe all hosts 
> support Python. You 
> should double check with whatever host you choose.
> 
> 
> ~Ramit
> 
> 
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.  
> ___
> 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] Create Library

2013-04-14 Thread Negin Nayeri
Hi!Im supposed to do a Library in Python and I don't even know how to begin! 
Please just help me. Like what kind of attributes do you think I should have, 
how do I store information? The file with the books and authors I must fix, do 
think I should write in txt format or like in Excel. Please help me.


Write a program used to handling simpler library routines. The program should 
be able to search for books in terms of both author and title. You should also 
be able to borrow and return books, put new books in the registry and remove 
the old books, and print a list on the screen of all books. The books will be 
sorted with respect to the author.The books are stored in a text file that you 
can write yourself. Your file does not contain more than ten books, but your 
program should be valid also for a large number of books.The program will 
remember which books are utlånadeäven if the user turns off and restarts the 
application.It can look some thing like this:Welcome to Adriana's Library:T 
search for titelF search by authorL Borrow BookR Return BookN Register new 
bookB remove book from registerA see a list of all booksQ quitWhat do you want 
to do? TWich title do you looking for? ...(write a list of all the books 
found)and so on.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Issue With a Python Game

2013-04-14 Thread John Bochicchio
I have a question about a game I am making. I finished the overall code,
but keep getting errors when I try to play. This is my most common error:
C:\Users\John\Documents\Python Games\Noah>python nickeladventuredemo.py
Traceback (most recent call last):
  File "nickeladventuredemo.py", line 451, in 
main()
  File "nickeladventuredemo.py", line 78, in main
levels = readLevelsFile('levels.txt')
  File "nickeladventuredemo.py", line 371, in readLevelsFile
assert startx != None  and starty!= None, 'Level %s (around line %s) in
%s i
s missing a "@" or "+" to mark the start point.' % (levelNum+1, lineNum,
filenam
e)
AssertionError: Level 1 (around line 10) in levels.txt is missing a "@" or
"+" t
o mark the start point.

The Code:

import random, sys, copy, os, pygame

from pygame.locals import *



FPS = 30

WINWIDTH = 800

WINHEIGHT = 600

HALF_WINWIDTH = int(WINWIDTH / 2)

HALF_WINHEIGHT = int(WINHEIGHT / 2)



TILEWIDTH = 50

TILEHEIGHT = 85

TILEFLOORHEIGHT = 45



CAM_MOVE_SPEED = 5



OUTSIDE_DECORATION_PCT = 20



BRIGHTBLUE = ( 0, 170, 255)

WHITE  = (255, 255, 255)

BGCOLOR = BRIGHTBLUE

TEXTCOLOR = WHITE



UP = 'up'

DOWN = 'down'

LEFT = 'left'

RIGHT = 'right'





def main():

global FPSCLOCK, DISPLAYSURF, IMAGESDICT, TILEMAPPING,
OUTSIDECOMAPPING, BASICFONT, PLAYERIMAGES, currentImage



pygame.init()

FPSCLOCK = pygame.time.Clock()



DISPLAYSURF = pygame.display.set_mode((WINWIDTH, WINHEIGHT))



pygame.display.set_caption('Noah Nickel Adventure!')

BASICFONT = pygame.font.Font('freesansbold.ttf', 18)



IMAGESDICT = {'uncovered goal': pygame.image.load('RedSelector.png'),

  'covered goal': pygame.image.load('Selector.png'),

  'star': pygame.image.load('Star.png'),

  'corner': pygame.image.load('Wall Block Tall.png'),

  'wall': pygame.image.load('Wood Block Tall.png'),

  'inside floor': pygame.image.load('Plain Block.png'),

  'outside floor': pygame.image.load('Grass Block.png'),

  'title': pygame.image.load('star_title.png'),

  'solved': pygame.image.load('star_solved.png'),

  'princess': pygame.image.load('princess.png'),

  'boy': pygame.image.load('boy.png'),

  'catgirl': pygame.image.load('catgirl.png'),

  'horngirl': pygame.image.load('horngirl.png'),

  'pinkgirl': pygame.image.load('pinkgirl.png'),

  'rock': pygame.image.load('Rock.png'),

  'short tree': pygame.image.load('Tree_Short.png'),

  'tall tree': pygame.image.load('Tree_Tall.png'),

  'ugly tree': pygame.image.load('Tree_Ugly.png')}



TILEMAPPING = {'X': IMAGESDICT['corner'],

   '#': IMAGESDICT['wall'],

   'o': IMAGESDICT['inside floor'],

   ' ': IMAGESDICT['outside floor']}



OUTSIDECOMAPPING = {'1': IMAGESDICT['rock'],

'2': IMAGESDICT['short tree'],

'3': IMAGESDICT['tall tree'],

'4': IMAGESDICT['ugly tree']}

#Super important to remember:

#DEAR GOD REMEMBER THIS IS AN INDEX OF PLAYER IMAGES.

currentImage = 0

PLAYERIMAGES = [IMAGESDICT['princess'],

IMAGESDICT['boy'],

IMAGESDICT['catgirl'],

IMAGESDICT['horngirl'],

IMAGESDICT['pinkgirl']]

startScreen()



levels = readLevelsFile('levels.txt')

currentLevelIndex = 0



while True:

result = runLevel(levels, currentLevelIndex)



if result in ('solved', 'next'):

currentLevelIndex += 1

if currentLevelIndex >= len(levels):

currentLevelIndex = 0



elif result == 'back':

currentLevelIndex -= 1

if currentLevelIndex <0:

currentLevelIndex = len(levels)-1



elif result == 'reset':

pass





def runLevel(levels, levelNum):

global currentImage

level0bj = levels[levelnum]

map0bj = decorateMap(level0bj['map0bj'],
level0bj['startState']['player'])

gameState0bj = copy.deepcopy(level0bj['startState'])

mapNeedsRedraw = True

levelSurf = BASICFONT.render('Level %s of %s' % (level0bj['levelNum']
+1, totalNumOfLevels), 1, TEXTCOLOR)

levelRect = levelSurf.get_rect()

levelRect.bottomleft = (20, WINHEIGHT - 35)

mapWidth = len(map0bj) * TITLEWIDTH

mapHeight = (len(map0bj[0]) - 1) * (TITLEHEIGHT - TILEFLOORHEIGHT) +
TILEHEIGHT

MAX_CAM_X_PAN = abs(HALF_WINHEIGHT - int(mapHeight / 2)) + TILEWIDTH

MAX_CAM_Y_PAN = abs(HALF_WINWIDTH - int(mapWidth / 2)) + TILEHEIGHT



levelIsComplete = False

camera0ffsetX = 0

camera0ffsety = 0

cameraUp = False

cameraDown = False

cameraLeft = False

cameraRight = False



while

Re: [Tutor] Issue With a Python Game

2013-04-14 Thread Mark Lawrence

On 13/04/2013 14:13, John Bochicchio wrote:

I have a question about a game I am making. I finished the overall code,
but keep getting errors when I try to play. This is my most common error:
C:\Users\John\Documents\Python Games\Noah>python nickeladventuredemo.py
Traceback (most recent call last):
   File "nickeladventuredemo.py", line 451, in 
 main()
   File "nickeladventuredemo.py", line 78, in main
 levels = readLevelsFile('levels.txt')
   File "nickeladventuredemo.py", line 371, in readLevelsFile
 assert startx != None  and starty!= None, 'Level %s (around line
%s) in %s i
s missing a "@" or "+" to mark the start point.' % (levelNum+1, lineNum,
filenam
e)
AssertionError: Level 1 (around line 10) in levels.txt is missing a "@"
or "+" t
o mark the start point.

The Code:
import random, sys, copy, os, pygame



I've stripped the remaining 450 lines of code as it's got the dread 
double spaced google disease, please see my signature.  You're also far 
more likely to get responses if your question follows the guidelines 
given here http://www.sscce.org/, particularly if someone already has 
pygame installed, which I don't.


However I did note one area where you can simplfy your code.  You've 
many lines using this type of construct.


for i in range(len(ships)):
doSomething(ships[i])

There's rarely a need for this in Python.  Use this instead.

for ship in ships:
doSomething(ship)

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: [Tutor] creating dictionary from a list

2013-04-14 Thread eryksun
On Sun, Apr 14, 2013 at 12:46 PM, Saad Javed  wrote:
>
> As for the underscores, what happened is that I didn't voluntarily add the
> underscores to begin with. If you read the emails again, after Mark's answer
> about not looping, I asked that the dictionary created as a result of his
> code wasn't ordered.

You replied with a multipart MIME message that included both plain
text and HTML versions.

HTML:

if item.startswith((
  'Mon',
  'Tue',
  'Wed',
  'Thu',
  'Fri',
  'Sat',
  'Sun'))

Text:

item.startswith(
('Mon','Tue','**Wed','Thu','Fri','Sat','Sun'))**

I don't know how the  underline tags got in there. They aren't
in the quote in Mark's message. Either way, for the plain text part,
your email program substituted "**". Others substituted "__".

There'd be no problem if you didn't use rich text in the first place.
Email programs always manage to mangle HTML. Besides, it really has no
place whatsoever on this forum. I always reply in plain text here.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating dictionary from a list

2013-04-14 Thread Saad Bin Javed

On 04/14/2013 10:50 PM, eryksun wrote:


I don't know how the  underline tags got in there. They aren't
in the quote in Mark's message. Either way, for the plain text part,
your email program substituted "**". Others substituted "__".

There'd be no problem if you didn't use rich text in the first place.
Email programs always manage to mangle HTML. Besides, it really has no
place whatsoever on this forum. I always reply in plain text here.


I've set changed settings in thunderbird to send plain text emails to 
python.org domain. Hopefully it won't be an issue again!


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


Re: [Tutor] Issue With a Python Game

2013-04-14 Thread Walter Prins
Hi John,

On 10 April 2013 15:21, John Bochicchio  wrote:

> I have a question about a game I am making. I finished the overall code,
> but keep getting errors when I try to play. This is my most common error:
> C:\Users\John\Documents\Python Games\Noah>python nickeladventuredemo.py
> Traceback (most recent call last):
>   File "nickeladventuredemo.py", line 451, in 
> main()
>   File "nickeladventuredemo.py", line 78, in main
> levels = readLevelsFile('levels.txt')
>   File "nickeladventuredemo.py", line 371, in readLevelsFile
> assert startx != None  and starty!= None, 'Level %s (around line %s)
> in %s i
> s missing a "@" or "+" to mark the start point.' % (levelNum+1, lineNum,
> filenam
> e)
> AssertionError: Level 1 (around line 10) in levels.txt is missing a "@" or
> "+" t
> o mark the start point.
>
> The error has something to do with the levels. I will attach the code and
> levels, as they are fairly long.
>

Firstly please next time include a segment of the failing code in the email
-- not everyone is prepared to or can be bothered to download and wade
through a large source file just to get to the bottom of an program error.

Secondly, re your your first assertion statement: it assumes that the
problem is due to a problem in the levels.txt file, which is not the case
here.  You'd do better IMHO to maybe not be so creative/presumptuous with
 the error message, and rather have it report exactly what the actual
assertion conditions (and maybe variable values at the time) is that failed
(in this case values of startx, starty.)   You might also consider rather
using Exceptions here.

All that said, the problem is you have the code throwing the exception at
the wrong level of indent.  You need to de-indent all the assert statements
as well as the code that follows up to but excluding the return statement
so that it's at the same level of the first "for" loop.  (Differently put,
the reason the assertion is likely failing is because you're doing your
asserts before the loops have finished processing/reading your mapObj. You
presumably want the asserts once the mapObj's been finished processing by
the loop.)

As an aside,  the next failure you'll likely run into is the third assert,
which expects len(stars) >= len(goals), which I assume will fail as you are
not reading anything into "stars" list anywhere as you do for  goals.

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


Re: [Tutor] Create Library

2013-04-14 Thread Dave Angel

On 04/08/2013 09:31 PM, Negin Nayeri wrote:

Hi!Im supposed to do a Library in Python and I don't even know how to begin! 
Please just help me. Like what kind of attributes do you think I should have, 
how do I store information? The file with the books and authors I must fix, do 
think I should write in txt format or like in Excel. Please help me.


Write a program used to handling simpler library routines. The program should 
be able to search for books in terms of both author and title. You should also 
be able to borrow and return books, put new books in the registry and remove 
the old books, and print a list on the screen of all books. The books will be 
sorted with respect to the author.The books are stored in a text file that you 
can write yourself. Your file does not contain more than ten books, but your 
program should be valid also for a large number of books.The program will 
remember which books are utlånadeäven if the user turns off and restarts the 
application.It can look some thing like this:Welcome to Adriana's Library:T 
search for titelF search by authorL Borrow BookR Return BookN Register new 
bookB remove book from registerA see a list of all booksQ quitWhat do you want 
to do? TWich title do you looking for? ...(write a list of all the books 
found)and so on.  




The formatting of that message sure got messed up.   Two very long 
lines.  You must have sent the message as html, instead of text.


Your assignment does NOT say you're supposed to create a Library.  It 
says you're supposed to create routines that might be used in a library.


It DOES tell you how to store your information;  use a text file.




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


[Tutor] (no subject)

2013-04-14 Thread Soliman, Yasmin
Hi everyone. I just need to know why this programs tells me End is not defined, 
what can I o to fix this issue? Thanks in advance.

hrList=[]
while True:
heartrate= float(input('Enter heart rate as beats per min: '))
hrList.append(heartrate)

if heartrate=='End':
print '\nThank you for using this program! Bye.'
break 

total_sum = 0;
length = len(hrList)

for i in range(0, length):
total_sum += hrList[i]

average = total_sum / length

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


Re: [Tutor] (no subject)

2013-04-14 Thread Dave Angel

On 04/14/2013 08:35 PM, Soliman, Yasmin wrote:

Hi everyone. I just need to know why this programs tells me End is not defined, 
what can I o to fix this issue? Thanks in advance.

hrList=[]
while True:
 heartrate= float(input('Enter heart rate as beats per min: '))
 hrList.append(heartrate)

 if heartrate=='End':
 print '\nThank you for using this program! Bye.'
 break

 total_sum = 0;
 length = len(hrList)

 for i in range(0, length):
 total_sum += hrList[i]

 average = total_sum / length

 print average




I can't see any place there where such an error might occur.  But I can 
see where you forgot the parens in the call to print().


You might get better advice by telling us the Python version, and the 
complete error message traceback.  That'll show us exactly what was 
executing when the exception happened.


Oh wait.  Perhaps you were running Python 2.x, rather than 3.x.  In that 
case, you should have used raw_input(), not input.  Input will eval 
whatever the user types, and if he types "End" he'll get an error:


Enter heart rate as beats per min: End
Traceback (most recent call last):
  File "soliman2.py", line 6, in 
heartrate= float(input('Enter heart rate as beats per min: '))
  File "", line 1, in 
NameError: name 'End' is not defined

Once you fix that, you'll get another error.

Enter heart rate as beats per min: End
Traceback (most recent call last):
  File "soliman2.py", line 6, in 
heartrate= float(raw_input('Enter heart rate as beats per min: '))
ValueError: could not convert string to float: End

That's because you try to convert the string "End" into an integer 
before you check it for the terminating value.  You want to do the 
raw_input first, then the check for End, then convert to int, then 
append and print the stuff.



Alternatively, you could just tell the user to enter "0" when he wants 
to quit.






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


[Tutor] Scheduling Python Execution

2013-04-14 Thread Zaki Akhmad
Hi all,

I'd like to execute python script for specific times. I prefer not to
use cron, since this times will be very varies.

Example, my requirement is, this python script will execute at:

13:00:00
14:05:00
14:35:00
15:20:00

I know this is gonna be a long script to run. Check the time.ctime()
then execute. Is designing with this approach isn't good? Since it
will be a long script running.

I've read the sched module.

And the enter module has delay argument. So is better that I calculate
the delay rather than the ctime to execute?

Regards,

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