Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96166
License: OTHER
1
"""This module contains a code example related to
2
3
Think Python, 2nd Edition
4
by Allen Downey
5
http://thinkpython2.com
6
7
Copyright 2015 Allen Downey
8
9
License: http://creativecommons.org/licenses/by/4.0/
10
"""
11
12
from __future__ import print_function, division
13
14
15
def do_twice(func, arg):
16
"""Runs a function twice.
17
18
func: function object
19
arg: argument passed to the function
20
"""
21
func(arg)
22
func(arg)
23
24
25
def print_twice(arg):
26
"""Prints the argument twice.
27
28
arg: anything printable
29
"""
30
print(arg)
31
print(arg)
32
33
34
def do_four(func, arg):
35
"""Runs a function four times.
36
37
func: function object
38
arg: argument passed to the function
39
"""
40
do_twice(func, arg)
41
do_twice(func, arg)
42
43
44
do_twice(print, 'spam')
45
print('')
46
47
do_four(print, 'spam')
48
49