You are on page 1of 3

Python 2.

7_sample main _ function call to function Written by Bernster1 We know already that 'variables' store values and are also used to directly 'call' on functions. Functions can also 'call' other functions. This is a call to a function; fredOne() We just state the function name with () at the end. There's no need for ':' to be included as we aren't declaring anything. We are just making a 'call'. When any function is 'called', the program will run it. Let's have a menu item call on a function. Our menu is already within the function 'main', so this will prove the 'function call to function'. Here is a simple function followed by 'main' with a shortened 'menu' Try menu item 2 # 1st you'll need these; import os import os.path # then you'll need this; #==================================================== def cls(): os.system(['clear','cls'][os.name == 'nt']) # use 'cls()' to call 'clear screen' when you run a menu item. #==================================================== # here's a sample function def simpleCascade(): linestooutput = 4 stopcount = 0 inputline = 1 lineplus = '' # now process the main part of the input line and give the values to newpars e newparse = '' # this gets the values of the input line # now process lastparse angle with the angle of the newparse to find the inc idence. lastparse = '' addtoparse = '' # this gets the angle of incidence added to the list parseout = '' # now send parseout to the fifo, to test just print to screen # the parseout should always be one step behind the newparse line # when parseout is sent, assign last parse with the value of newpass before looping again. # lastparse should retain the value given until it's re-assigned again at th e end of the next # loop. while stopcount != linestooutput: if inputline <= linestooutput: newparse = 'inputline',inputline # line parsing would happen here, find the angle lastparse = 'angle,',newparse addtoparse = 'incidence,', lastparse parseout = addtoparse

stopcount = stopcount + 1 lineplus = inputline + 1 print newparse print lastparse # find the angle of incidence, would happen here inputline = lineplus # make the change to the input line print parseout print '\n\n\nThe program just ran a simple cascade process.' toleave = raw_input("\nPressing Enter, starts the return to the menu .. :") # here's main def main(): item = None while item != "0": cls() print """ ============= THIS IS THE MAIN MENU Type an item number, then press Enter to run it """ print " 1. ....IMPORT\n" print " 2. ....PROCESS\n" print " 0. ....CLOSE" print """ ===================================================== """ item = raw_input ("\n\nType an Item number: ") if item == "1": cls() print "\n\nFile import could run here\n" goback = raw_input ('\n\nPress enter .... Return to Main Menu: ') if goback == "\n": pass elif item == "2": cls() begin = raw_input ('\n\nPress enter to start the function: ') cls() simpleCascade() goback = raw_input ('\n\nPress enter again: ') if goback == "\n": pass # here we call 'main' main() ================

You might also like