[Tutor] Character creator program

spir ☣ denis.spir at gmail.com
Wed May 12 19:01:35 CEST 2010


On Wed, 12 May 2010 13:33:46 +0100
"Ben Millane" <ben at richmondtravelsolihull.co.uk> wrote:

> Ok first off here is a link to my code
> 
> http://pastie.org/956909
> 
> My problem is, that although I have the program working how I want it to work in general. I still have an issue with the user input section. If my user inputs any of the options from the menu, the program works as it should. But say if the user accidentally pressed enter with no option entered the program ends with an error message, or if they put in the incorrect number or a letter, it returns an error.
> 
> What I would like to happen is for a "Choice invalid, please choose another option" message to come up if this happens, but I am unsure how to put this in.
> 

You just need to add an "else" block to your main choice menu, coping with that special case: print a message and "continue", meaning go back to menu. But: I did not read in the detail, still there's something wrong in the overall structure. Namyly with "if total < 30" in the middle of the menu. Probably your app does not work in particuliar cases, and if does anyway, there is something wrong in the structure.

Also, you may consider putting all the hardcoded data in statements (esp. character skill points) into proper data structures like lists or better dictionaries in your case... in you don't know yet about custom classes (your app would be pleased with a Character class, indeed).

Even if you don't use a class, the logic of your app should not be hand-coded in a main menu, but in dedicated functions like
   addPoints(skill, count)

All together, the aim is to make a clear structure where the *logic* of the app obviously appears.


Denis
________________________________

vit esse estrany ☣

spir.wikidot.com


More information about the Tutor mailing list