-1
print'Personal information, journal and more to come'
x = raw_input()
if x ==("personal information"): 
 print' Edward , Height: 5,10 , EYES: brown , STATE: IL TOWN:  , SS:'
if x ==("journal"):
 read = open('C:\\python\\foo.txt' , 'r')
 name = read.readline()
 print (name)

how do i loop or keep this code running without telling me that something wasnt defined? for example if i type in personal information and i get to my personal information then i want to type journal and then go to journal?

  • Perhaps I'm not understanding your question. Why can't you just put `while True:` in front of x = raw_input(), and indent everything? – Max Jul 30 '12 at 21:36
  • Why are you putting parentheses around your quoted strings to compare? – Wooble Jul 30 '12 at 21:37
  • lets say i type in personal information and it shows me my personal information, then i want to type in journal but it says name journal is not defined. – Edward LaPiere Jul 30 '12 at 21:38
  • you get the error `NameError: name 'journal' is not defined`? not with the above code. Is there code you're not posting? – David Robinson Jul 30 '12 at 21:39
  • 1
    He's getting that error because his script has ended and he's talking to the Python interactive prompt. – kindall Jul 30 '12 at 22:00

1 Answers1

0

I don't know what really is your problem, but this should be helpful:

print'Personal information, journal and more to come'
while True:
    x = raw_input()
    if x =="personal information": 
        print' Edward , Height: 5,10 , EYES: brown , STATE: IL TOWN:  , SS:'
    elif x =="journal":
        read = open('C:\\python\\foo.txt' , 'r')
        name = read.readline()
        print (name)
    else:
        break
applicative_functor
  • 4,926
  • 2
  • 23
  • 34