Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中调用函数内部的函数?_Python_Python 3.x - Fatal编程技术网

在python中调用函数内部的函数?

在python中调用函数内部的函数?,python,python-3.x,Python,Python 3.x,试图找到一种方法来调用函数中的每个函数,thirdQues。我不希望它们是全局的,当我显示它们嵌套在main中的第三个队列中时,会不断收到意外的缩进错误。我还计划将thirdQues嵌套在与其大小相同的函数中。谢谢你的帮助 import time def thirdQues(a = ("Questions_7.txt"), b = ("Questions_8.txt"), c = ("Questions_9.txt")): myName=("none") d

试图找到一种方法来调用函数中的每个函数,thirdQues。我不希望它们是全局的,当我显示它们嵌套在main中的第三个队列中时,会不断收到意外的缩进错误。我还计划将thirdQues嵌套在与其大小相同的函数中。谢谢你的帮助

import time
def thirdQues(a = ("Questions_7.txt"), b = ("Questions_8.txt"), c = ("Questions_9.txt")):
        myName=("none")



        def intro3():
                Intro1 = open(Intro3.txt, "r")
                print(Intro1)

        def announce3(): 
                input()
                print('"TT(Announcing):.... BIENVIENDOS AL CORO CIRCUIT! HOY TENENMOS.....(Welcome to the Coro Circuit! Today we have.....)"')
                time.sleep(5)
                print('" El jefe..... El mysterio..... El campeón de peso pesado......(The boss....... The mysterious........ the heavy weight champion....."')
                time.sleep(5)
                print('"Senor........ Diego!"')
                time.sleep(3)
                print('(Crowd electrifies the arena in excitement)') 
                print('Diego:(Staring you down with a neutral experssion and arms crossed): \n "HMPH.... "')
                input() 


                print('"TT(Announcing): ANNNND.....HONING IN FROM SU CASA CUIDAD, (Their hometown)"')
                time.sleep(3)
                print('".....VEN EL UN.....(Comes the one.....)"')
                time.sleep(2)
                print('"........EL SOLO......(The ONLY.....)"')
                time.sleep(3)
                print('"........CON DOS GANADORS DESPUES SU CINTURON......(With 2 wins under their belt.....)"')
                time.sleep(3)
                print('".......El' +(myName)+ '!!!!') 
                input()


                print('(The same woman from the last matches is now holding a small Japanese flag and blowing kisses towards you.') 
                print('TT: VAMOS A EMPEZAR CORO CIRCUIT! (LET"S GO CORO CIRCUIT!)')
                input()
        #I wanted to have the print statements timed instead of reading the announcements from a file to add depth.
        def Preguntas3():       
                text_file = open(a, "r")
                wholefile = text_file.read()
                print(wholefile)

                ans = ''    
                ans = input()
                yes = []
                yup = []
                right = [] 
                print('TT: Eres Cierto? (Are you sure? Be sure to properly spell out your answer.) \n (TYPE Y OR N)')
                sure = ''
                sure = input()
                if sure == str('y' or 'Y'):
                        answer = ''
                        answer=str(ans)
                else:
                        print('"TT: Lo siento, could you say that again?"')

                        answer = input() 
                time.sleep(3)
                if answer == str('To win is to adapt.'): 
                        print('..... '+(myName)+ ' seals the first hit!')
                        time.sleep(3)
                        print('TT: Whoa, that is an outrageous uppercut!')
                        time.sleep(4)
                        print('Diego:......(Gives you a dark look and retains his stance)')
                        time.sleep(3)
                        print('TT: Seems you cannot win without adaptation....') 
                        print('TT: Next question')
                        yes=['Si']

                else:
                        print('TT: And Diego swipes the stage with a gizalle punch!')
                        time.sleep(3)
                        print('TT: Estoy sin palabras!!! (I am speechless!)') 
                        time.sleep(4)
                        print('Diego:..... Eres loco.... (You are foolish.)')
                        time.sleep(3)
                        print('TT: Next Question!')

                input()

                text_file = open(b , "r")
                wholefile = text_file.read()
                print(wholefile)

                ans = ''    
                ans = input()
                correct = []
                print('TT: Eres Cierto? (Are you sure? Be sure to properly spell out your answer.) (FULL SENTENCES NEED PERIODS.) \n (TYPE Y OR N)')
                sure = ''
                sure = input()
                if sure == str('y' or 'Y'):
                        answer = ''
                        answer=str(ans)
                else:
                        print('"TT: Lo siento, could you say that again?"')

                        answer = input() 
                time.sleep(3)
                if answer == str('Believe in yourself.'): 
                        print('.....(Crowd goes rampid).... TT: '+(myName)+' tiene el fuego! (Has the fire!) ')
                        time.sleep(3)
                        print('TT: Gosh! What a spectacular Haymaker!')
                        time.sleep(4)
                        print('Diego:.........(Looks away briefly)')
                        time.sleep(1)
                        print('TT: Next question')
                        yup=['Tu']

                else:
                        print('......(Crowd goes insane) TT: We have got a pull counter de Senor Diego!')
                        time.sleep(3)
                        print('TT: NO PUEDO MIRAR, NO PUEDO MIRAR! ( I cannot look! I cannot look!')
                        time.sleep(4)
                        print('Diego:.......Eres un inutil....(....You suck....') 
                        time.sleep(3)
                        print('TT: IT IS TIME FOR THE FINAL QUESTION OF THE CORO CIRCUIT!!!')
                        time.sleep(2)
                        print('(The Crowd is shuffling like fireworks!)') 
                        time.sleep(4)
                        input()

                        print('(Diego stares at you with the harshest eyes you have ever seen in your life.)')
                        print('(He retains his stance and looks as if he is about to parry)') 
                        print('(You swallow deeply intimadation and discover what you must do next...)')

                text_file = open(c, "r")
                wholefile = text_file.read()
                print(wholefile)

                ans = ''    
                ans = input()
                print('TT: Eres Cierto? (Are you sure? Be sure to properly spell out your answer.) \n (TYPE Y OR N)')
                sure = ''
                sure = input()
                if sure == str('y' or 'Y'):
                        answer = ''
                        answer=str(ans)
                else:
                        print('"TT: Lo siento, could you say that again?"')

                        answer = input() 
                time.sleep(3)
                if answer == str('As always'): 
                        print('And....'+(myName)+' GETS THE HIT!')
                        time.sleep(3)
                        print('TT:..........')
                        time.sleep(4)
                        print('Diego:..........')
                        time.sleep(4)
                        print('(Crowd:.........!)')
                        time.sleep(4)
                        print('Woman in the crowd: Anata o shinrai shite imasu!!(I believe in you!)') 
                        input()
                        right=['Ganas']

                else:
                        print('TT: Anddd: Diego GETS THE LAST HIT!!!!')
                        time.sleep(3)
                        print('TT:..........')
                        time.sleep(4)
                        print('(Crowd:.........!)')
                        time.sleep(4)
                        print('Woman in the crowd:.......(She ducks her head in sadness.) ')
                        time.sleep(4)
                        print('Diego:.......Soy el mejor......(....I am the best.....) ')
                        input()

                print('(.........You have had enough of this and decide to charge him force with all you might. \n He does the same....)')
                input() 
                print('TT: AY DIAS MIA! (OH MY GOD!) THEY ARE GOING AT IT RANDOMLY NOW NON STOP!?!.... GONNA HAVE TO DECLARE THE WINNER IN.......') 
                time.sleep(2)

                advance = (yes + yup + right) 
                if advance == ['Si','Tu','Ganas'] or ['Si', 'Tu',] or ['Tu', 'Ganas'] or ['Si', 'Ganas'] :
                                print('TT:10')
                                time.sleep(1)
                                print('TT:9')
                                time.sleep(1)
                                print('TT:8')
                                time.sleep(1)
                                print('TT:7')
                                time.sleep(1)
                                print('TT:6')
                                time.sleep(1)
                                print('TT:5')
                                time.sleep(1)
                                print('TT:4')
                                time.sleep(2)
                                print('TT:3')
                                time.sleep(2)
                                print('TT:2')
                                time.sleep(4) 
                                print('......1')
                                time.sleep(1) 
                                print('TT: AND THE GANADOR(Winner) ISSSSSSSS,' , +(myName)+ '!' 'Congratulations! YOU HAVE WON THE CORO CIRCUIT!')
                                print('Diego:........ Anata wa jibun o shinjite...... (He bows down for you and then vanishes in thin air.)') 
                else:
                                print('TT:10')
                                time.sleep(1)
                                print('TT:9')
                                time.sleep(1)
                                print('TT:8')
                                time.sleep(1)
                                print('TT:7')
                                time.sleep(1)
                                print('TT:6')
                                time.sleep(1)
                                print('TT:5')
                                time.sleep(1)
                                print('TT:4')
                                time.sleep(2)
                                print('TT:3')
                                time.sleep(2)
                                print('TT:2')
                                time.sleep(4) 
                                print('......1')
                                time.sleep(1) 
                                print('TT: AND THE GANADOR(Winner) ISSSSSSS, DIEGO! Congratulations!')
                                input()


##                                print('Ricka: Me das asco........\n(You disgust me...... \n(He lifts his arms and glares at the crowd)')
##                                input()
##                                print('Ricka: RICKAKAKKKKAKAKKAAKKAKKAKAKKKAAKA!')
##                                input()
##                                print('(...... you pass out, unable to bear with blows of your opponent.... \n Until you wake up from this nightmare.... \n ')
##                                input()
##                                print('(Reality sets in, it is only 2:30 AM and you ask yourself.....)')
####                playAgain = 'yes'
##                while playAgain == 'yes' or playAgain == 'y':
##                        firstQues()
##                        a = ("Questions1.txt")
##                        b = ("Questions_2.txt")
##                        c = ("Questions_3.txt")
##                print('Do you want to go back to bed and finish this dream? \n (TYES YES OR Y) Or do you want to wake up and start your miserable day? \n (TYPE NO OR N)')
##                playAgain=input()
##              
def main():
        thirdQues(a = "Questions_7.txt",  b = "Questions_8.txt" ,c = "Questions_9.txt")
                intro3()
                announce3()
                Preguntas3()
main() 

这个缩进是错误的:

def main():
        thirdQues(a = "Questions_7.txt",  b = "Questions_8.txt" ,c = "Questions_9.txt")
                intro3()
您不能在此缩进
intro3()


除此之外,缩进使用4个空格,而不是8个空格。两者在语法上都有效,但始终使用4个空格。它只是看起来更好,每个人都习惯了。

您没有因为尝试嵌套函数而收到错误;这在语法上是有效的。你的缩进,是我们出错的原因。太离题了。我的缩进是在主程序中还是在整个程序中?请把你遇到的问题贴出来。不要只是扔掉一堆代码。还有,为什么把字符串放在括号里?e、 g.
myName=(“无”)
?您的缩进在
main
中肯定是关闭的。无论如何,您正在
main
的范围内调用
intro3
announce3
Preguntas3
,但它们不在
thirdQues
的范围之外。从
thirdQues
返回它们,并将它们分配给
main
中作用域中的某个对象,然后调用它们。@RickBould Python缩进是四个空格。在需要缩进的地方使用8。停止使用制表符,或者使用自动将制表符转换为空格的编辑器,或者只敲出四个空格。但请看一下常规Python程序的格式。