有没有办法在函数中添加函数?我目前正在制作一个游戏,它会让我的脚本更有条理!
我当前脚本的一个示例:
def LVL1_TUTORIAL_07__C_USERS_MRX():
print
choice = raw_input('C:\Users\Mr. X>')
if choice.lower() == 'help':
print
print ' dir - Allows you to see the available files and directories in the current directory.'
print ' cd - (Change Directory) is a command used to switch directories in MS-DOS and the Windows command line.'
print ' search - Searching'
print ' connect - connect + name of the server you want to connect'
LVL1_TUTORIAL_07__C_USERS_MRX()
if choice.lower() == 'cls':
os.system('cls')
LVL1_TUTORIAL_07__C_USERS_MRX()
if choice.lower() == 'cd':
print 'C:\Users\Mr. X'
LVL1_TUTORIAL_07__C_USERS_MRX()
if choice.lower() == 'cd.':
print
LVL1_TUTORIAL_07__C_USERS_MRX()
if choice.lower() == 'cd..':
print
if choice.lower() == 'cd contacts':
LVL1_TUTORIAL_07__C_USERS_MRX_CONTACTS()
if choice.lower() == 'cd desktop':
LVL1_TUTORIAL_07__C_USERS_MRX_DESKTOP()
if choice.lower() == 'cd documents':
LVL1_TUTORIAL_07__C_USERS_MRX_DOCUMENTS()
if choice.lower() == 'cd downloads':
LVL1_TUTORIAL_07__C_USERS_MRX_DOWNLOADS()
if choice.lower() == 'cd favorites':
LVL1_TUTORIAL_07__C_USERS_MRX_FAVORITES()
if choice.lower() == 'cd links':
LVL1_TUTORIAL_07__C_USERS_MRX_LINKS()
if choice.lower() == 'cd music':
LVL1_TUTORIAL_07__C_USERS_MRX_MUSIC()
if choice.lower() == 'cd pictures':
LVL1_TUTORIAL_07__C_USERS_MRX_PICTURES()
if choice.lower() == 'cd videos':
print
print 'test'
time.sleep(2)
LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()
def LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS():
print
choice = raw_input('C:\Users\Mr. X\Videos>')
if choice.lower() == 'help':
print 'help'
if choice.lower() == 'cls':
os.system('cls')
LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()
if choice.lower() == 'cd folder 1':
LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS_FOLDER1()
def LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS_FOLDER1():
print
choice = raw_input('C:\Users\Mr. X\Videos>')
if choice.lower() == 'help':
print 'help'
if choice.lower() == 'cd..':
LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()
if choice.lower() == 'cd..':
LVL1_TUTORIAL_07__C_USERS_MRX()
return LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS_FOLDER1()
return LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()
if choice.lower() == 'dir':
print
print ' Volume in drive C has no label.'
print ' Volume Serial Number is 57GE-4AFB'
print
print ' Directory of C:\Users\Mr. X'
print
print '01.01.2013 00:00 <DIR> .'
print '01.01.2013 00:00 <DIR> ..'
print '01.01.2013 00:00 <DIR> Contacts'
print '01.01.2013 00:00 <DIR> Desktop'
print '01.01.2013 00:00 <DIR> Documents'
print '01.01.2013 00:00 <DIR> Downloads'
print '01.01.2013 00:00 <DIR> Favorites'
print '01.01.2013 00:00 <DIR> Links'
print '01.01.2013 00:00 <DIR> Music'
print '01.01.2013 00:00 <DIR> Pictures'
print '28.07.2013 15:57 0 telnet'
print '01.01.2013 00:00 <DIR> Videos'
print ' 1 File(s) 0 bytes'
print ' 11 Dir(s) 53 687 091 200 bytes free'
print
LVL1_TUTORIAL_07__C_USERS_MRX()
else:
print
print 'wrong'
time.sleep(2)
return LVL1_TUTORIAL_07__C_USERS_MRX()
LVL1_TUTORIAL_07__C_USERS_MRX()
然后我收到此错误消息:
UnboundLocalError: local variable 'LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS' referenced before assignment
File "C:\Users\Stig Arne\Desktop\HACKER\HACKER.py", line 3715, in <module>
LVL1_TUTORIAL_07__C_USERS_MRX()
File "C:\Users\Stig Arne\Desktop\HACKER\HACKER.py", line 3656, in LVL1_TUTORIAL_07__C_USERS_MRX
LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()
我不太确定出了什么问题。我真的希望这能奏效,因为它会让我的工作更轻松。据我所知,这可能只是一个导致问题的小错字。
我真的希望这里有人能看到错误!
谢谢!