Think Python: How to Think Like a Computer Scientist
Format: PDF / Kindle (mobi) / ePub
If you want to learn how to program, working with Python is an excellent way to start. This hands-on guide takes you through the language a step at a time, beginning with basic programming concepts before moving on to functions, recursion, data structures, and object-oriented design. This second edition and its supporting code have been updated for Python 3.
Through exercises in each chapter, you’ll try out programming concepts as you learn them. Think Python is ideal for students at the high school or college level, as well as self-learners, home-schooled students, and professionals who need to learn programming basics. Beginners just getting their feet wet will learn how to start with Python in a browser.
- Start with the basics, including language syntax and semantics
- Get a clear definition of each programming concept
- Learn about values, variables, statements, functions, and data structures in a logical progression
- Discover how to work with files and databases
- Understand objects, methods, and object-oriented programming
- Use debugging techniques to fix syntax, runtime, and semantic errors
- Explore interface design, data structures, and GUI-based programs through case studies
of the display. >>> right_justify('allen') allen Exercise 3-4. A function object is a value you can assign to a variable or pass as an argument. For example, do_twice is a function that takes a function object as an argument and calls it twice: def do_twice(f): f() f() Here’s an example that uses do_twice to call a function named print_spam twice. def print_spam(): print 'spam' do_twice(print_spam) Type this example into a script and test it. Modify do_twice so that it takes two
looks like polygon, but we can’t reuse polygon without changing the interface. We could generalize polygon to take an angle as a third argument, but then polygon would no longer be an appropriate name! Instead, let’s call the more general function polyline: def polyline(t, n, length, angle): for i in range(n): fd(t, length) lt(t, angle) Now we can rewrite polygon and arc to use polyline: def polygon(t, n, length): angle = 360.0 / n polyline(t, n, length, angle) def arc(t, r, angle): arc_length
the Holy Grail, and duration contains the run time of the movie, which is one hour 35 minutes. add_time figures out when the movie will be done. >>> start = Time() >>> start.hour = 9 >>> start.minute = 45 >>> start.second = 0 >>> duration = Time() >>> duration.hour = 1 >>> duration.minute = 35 >>> duration.second = 0 >>> done = add_time(start, duration) >>> print_time(done) 10:80:00 The result, 10:80:00 might not be what you were hoping for. The problem is that this function does not deal with
Acknowledgments graphical user interface, GUI greatest common divisor (GCD), Exercises grid, Exercises guardian pattern, Checking Types, Glossary, Debugging GUI, GUI, Glossary Gui module, GUI H Hand class, Inheritance, Class Diagrams hanging, My Program Hangs HAS-A relationship, Class Diagrams, Glossary, Class Diagrams hasattr function, Debugging, Debugging hash function, Dictionaries and Lists, Glossary, Hashtables hashable, Dictionaries and Lists, Glossary, Dictionaries and
New York and the Great Lakes, though it was chiefly found from Florida to the Carolinas. The Carolina parrot was mainly green with a yellow head and some orange coloring that appeared on the forehead and cheeks at maturity. Its average size ranged from 31–33 cm. It had a loud, riotous call and would chatter constantly while feeding. It inhabited tree hollows near swamps and riverbanks. The Carolina parrot was a very gregarious animal, living in small groups that could grow to several hundred