Coordinate Grid Points

James Stroud jstroud at mbi.ucla.edu
Mon Feb 5 18:36:08 EST 2007


Eric.Gabrielson at gmail.com wrote:
> Hello,
>        I am very knew to python and am attempting to write a program
> in python that a friend of mine is having to write in java. I am doing
> this for fun and would like some help as to how i can generate random
> coordinate points (x,y) and compare them with user inputted coordinate
> points. For example how will I be able to access the separate values,
> the x from the x,y position. I think I understand everything except
> 1)the random coordinate points 2) the getting the users inputted x and
> y values in one line ("Please guess a coordinate point from (1,1) to
> (20,20): ") as opposed to  ("Please enter an x value:" and "Please
> enter a y value") and finally 3) acessing the x value from the x,y
> coordinate function. the assignment description is located here http://
> www.cs.washington.edu/education/courses/142/07wi/homework/
> homework.html if you would like to see a more in depth discription of
> the game.
> 
> Many Thanks,
> Eric
> 

For the game described, the input is of the form "20 20", so (1) eval 
won't work and (2) regex is not needed. So you should use a healthy 
combo of map(), inpt.split(), int(), and inpt.strip() (assuming inpt is 
the string input). But not necessarily in the order listed.



More information about the Python-list mailing list