#Step 1: def print_monty_python(): print "Monty Python" print_monty_python() # this prints "Monty Python" print print_monty_python() # !!!!!????? ook de print result is er nog steeds !!!!!!?????? this results in None, because the function does not return anything #Step 2: def returning_monty_python(): Strvar = "Monty Python" return Strvar returning_monty_python() # this results in nothing print returning_monty_python() # this prints the returned value of the function #Step 3: def adding_100(n): Plus100 = n + 100 return Plus100 adding_100(200256) # this results in nothing print adding_100(200456) # this prints the returned value of the function #Step 4: def adding_two_numbers(n1,n2): sum = n1 + n2 return sum adding_two_numbers(2,3) # this results in nothing print adding_two_numbers(4,3) # this prints the returned value of the function #Step 4(b?): def using_a_previous_function(a,b,c): Multiplier = adding_two_numbers(a,b) Product = Multiplier * c return Product using_a_previous_function(2,3,4) # this results in nothing print using_a_previous_function(2,3,5) # this prints the returned value of the function #Step 5: def reading_a_file(path): ''' STEP 5: write a function called "reading_a_file" that: (a) takes the path to a file (in this case "gold_standard.txt" which is placed in this same directory) (b) opens the file (c) loops through the file and saves each line as an element in a list (d) returns the list Also call this function below this function to show that it works ''' #Step 6: def sanity_check(path2): ''' STEP 6: write a function called "sanity_check" that: (a) takes the path to a file (in this case "gold_standard.txt" which is placed in this same directory) (b) uses the function "reading_a_file" to open the file and to save all lines to a list (c) prints the length of the list (d) prints the first two elements (e) prints the final two elements (f) prints the list without duplicates (g) prints the list sorted on alphabet '''
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question