Re: [Tutor] python game error

2018-10-15 Thread Peter Otten
Alan Gauld via Tutor wrote: > On 15/10/18 08:57, Peter Otten wrote: > >> By the way, you do not need a map (dict) at all to implement a game like >> this, you may return the next scene directly. A sketch: >> >> class Bridge: >> def enter(self): >> ... >> action = ... >>

Re: [Tutor] python game error

2018-10-15 Thread Alan Gauld via Tutor
On 15/10/18 08:57, Peter Otten wrote: > By the way, you do not need a map (dict) at all to implement a game like > this, you may return the next scene directly. A sketch: > > class Bridge: > def enter(self): > ... > action = ... > if action == "jump off the bridge":

Re: [Tutor] python game error

2018-10-15 Thread Peter Otten
bob gailer wrote: > Python coding "trick"1 > when I build a map I omit the () after the class e.g. 'death' = Death, > ... and apply them to the item retrieved from the map. > > use a decorator to build the map dictionary: > > # the decorator function: > def

Re: [Tutor] python game error

2018-10-14 Thread bob gailer
More comments on code: guess = raw_input("[pod #]> ")     if int(guess) != good_pod: If user enters something that will not convert to integer an exception will be raised. For example >>> int('a') Traceback (most recent call last):   File "", line 1, in ValueError: invalid literal

Re: [Tutor] python game error

2018-10-14 Thread bob gailer
On 10/14/2018 1:42 PM, Mats Wichmann wrote: Hint here: don't use 'map' as your own variable name, since it's a built-in function. Absolutely, I am always warning others about this gotcha. In this case map is local to add_to_map so it does not affect then global namespace. The reason I used it

Re: [Tutor] python game error

2018-10-14 Thread Mats Wichmann
On 10/14/2018 10:08 AM, bob gailer wrote: > Python coding "trick"1  > when I build a map I omit the () after the class e.g. 'death' = Death, > ... and apply them to the item retrieved from the map. > > use a decorator to build the map dictionary: > > # the decorator

Re: [Tutor] python game error

2018-10-14 Thread bob gailer
More comments: User Friendly? I hope this game is not intended for actual use. No one will be able to guess the correct actions in a reasonable time. or 3 digit random code given 10 tries for any one code. I for one would give up pretty quickly. The original

Re: [Tutor] python game error

2018-10-14 Thread bob gailer
On 10/13/2018 4:25 AM, Mariam Haji wrote: ... Your problem intrigued me enough to spend some time "fixing" your program so it will compile with no errors and run at least the initial case where I entered "shoot!" Here are the problems I found: (line numbers refer to your original code) -

Re: [Tutor] python game error

2018-10-13 Thread Bob Gailer
suggestions: 1-Use triple-quoted strings: print """take the short-cut!""' 2 - make the program much simpler to start with. The usual approach to developing programs like this is to start simple get the simple things working right then add more complicated scene descriptions. Even better:

Re: [Tutor] python game error

2018-10-13 Thread Peter Otten
Mariam Haji wrote: > Hi guys, > > I am still on the learn python the hard way. > I built the below on python 2.7 and my OS is windows 7. > > I am getting this error: > Traceback (most recent call last): > File "ex43.py", line 205, in > a_game.play() > File "ex43.py", line 21, in play >

Re: [Tutor] python game error

2018-10-13 Thread Steven D'Aprano
On Sat, Oct 13, 2018 at 11:25:20AM +0300, Mariam Haji wrote: > Hi guys, > > I am still on the learn python the hard way. > I built the below on python 2.7 and my OS is windows 7. > > I am getting this error: > Traceback (most recent call last): > File "ex43.py", line 205, in >

[Tutor] python game error

2018-10-13 Thread Mariam Haji
Hi guys, I am still on the learn python the hard way. I built the below on python 2.7 and my OS is windows 7. I am getting this error: Traceback (most recent call last): File "ex43.py", line 205, in a_game.play() File "ex43.py", line 21, in play next_scene_name =