[Tutor] (no subject)

Adam Cripps kabads at gmail.com
Sat Sep 4 17:49:22 CEST 2004


----- Original Message -----
From: Jon Kolbe <jonnorkol at yahoo.com>
Date: Sat, 4 Sep 2004 08:40:26 -0700 (PDT)
Subject: [Tutor] (no subject)
To: tutor at python.org


I'm new to python, and I'm having some trouble. I'm trying to write a
program so people can make a character for a Risus game. Since the
cliches (skills) of the character have to be user-defined, I can't
make a list. I've gotten to where the user has to insert the name of
the cliche, but I've ran into this error
  
Traceback (most recent call last):
  File "<pyshell#38>", line 1, in -toplevel-
    risus()
  File "<pyshell#37>", line 15, in risus
    reply = input()
  File "<string>", line 0, in -toplevel-
NameError: name 'cook' is not defined 
  
Here's my program 
  
#Risus Character Generator
def risus():
 cliches = {}
 player = {}
 player['Name'] = raw_input("What is the Character's name? ")
 dice = input("How many dice will your character have? ")
 player['Title'] = raw_input("What is the Character's title? ")
 while dice > 0:
  print "Do you want to add a cliche? "
  print "1 Yes "
  print "2 No "
  reply = input() 
  if reply == 1:
   print "What is the name of the cliche? "
   reply = input()
   cliches = { 'cliche': "reply" }
   print "How many dice? "
   power = input()
   dice = dice-power
   cliches = { 'cliche': "power" }
   player[cliches] = power
  else:
   dice = 0
 print "You're done!"
 print character 
  
If any one can give me a hint on how to add user-input to a list,
thanks in advance
Jon


Something like this should get you the sort of thing you are aiming for:

cliche = []
power = raw_input ("What power would you like?")
cliche.Add(power)

This would store the input into the first 'slot' of the list (in this
case power[0]).

However, to me it sounds like your problem would better resolved with
an object oriented approach. Does anyone else think this might suit
Jon better?

Adam


More information about the Tutor mailing list