简体   繁体   中英

Calling functions inside a function in python?

Trying to find a way to call each function inside the function, thirdQues. I don't want them to be global, and keep receiving an unexpected indentation error when I show they are nested within thirdQues in the main. I also plan to nest thirdQues in functions around the same size as itself. Any help appreciated.

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() 

This indentation is wrong:

def main():
        thirdQues(a = "Questions_7.txt",  b = "Questions_8.txt" ,c = "Questions_9.txt")
                intro3()

You cannot indent intro3() here.

Besides that, use 4 spaces for indentation, rather than 8. Both are syntactically valid, but 4 spaces are always used. It just looks better and everyone is used to that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM