一个非常简单的while
循环语句会继续下面的程序,直到用户键入“exit”?
例如,
while response = (!'exit')
continue file
else
break
print ('Thank you, good bye!')
#I know this is completely wrong, but it's a try!
到目前为止我的文件:
#!/usr/bin/python
friends = {'John' : {'phone' : '0401',
'birthday' : '31 July',
'address' : 'UK',
'interests' : ['a', 'b', 'c']},
'Harry' : {'phone' : '0402',
'birthday' : '2 August',
'address' : 'Hungary',
'interests' : ['d', 'e', 'f']}}
response = raw_input("Please enter search criteria, or type 'exit' to exit the program: ").split()
try:
print "%s's %s is %s" % (response[0], response[1], friends[response[0]][response[1]])
except KeyError:
print "Sorry, I don't know about that. Please try again, or type 'exit' to leave the program: "