how to i loop the script so i can keep entering my options without an error on python [closed]

StackOverflow https://stackoverflow.com/questions/11729964

  •  23-06-2021
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top