Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

A Pythonic Adventure: From Python basics to a working web app
A Pythonic Adventure: From Python basics to a working web app
A Pythonic Adventure: From Python basics to a working web app
Ebook436 pages3 hours

A Pythonic Adventure: From Python basics to a working web app

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Time to take an adventure with friends! Team up with Erik and Simon to learn Python the easy way. This colorful book uses engaging questions and lively conversations to introduce computer programming to young readers one step at a time.

In A Pythonic Adventure, you will learn useful Python skills like:

  • Installing Python
  • Working with files
  • Creating text-based dialogs and menus
  • Using if/then, loops, lists, dictionaries, and input/output
  • Building web applications
  • Making your web apps look super professional

It’s fun to learn with friends! In A Pythonic Adventure you’ll meet Erik and Simon, two brothers who are just beginning their Python journey. Join them as they chat about the language, learn the basics, and build some cool programs. The book’s dialogue helps young programmers understand complex concepts much more easily. It's the perfect way for young programmers (and their parents) to get started.

There’s no boring lessons or dull exercises in this adventure. You’ll follow Erik and Simon’s questions and mistakes, discover how to write programs with a team, and get a chance to create applications you can use in your daily life. By the time they’re done reading, young learners will not only know how to write code, they’ll know how to think about problems like professional developers. All code in this book runs on Mac, Windows, Linux, and Raspberry Pi.

About the technology

Computer programming is an adventure, full of new experiences, challenges, triumphs, and mistakes. In A Pythonic Adventure, you’ll join brothers Erik and Simon as they learn to create their first Python program. Written especially for young readers, this book is the perfect introduction to a skill that will last a lifetime!

About the book

A Pythonic Adventure teaches you to code by asking questions, making errors, and trying out different solutions—just like in real life. As you go, you’ll create a web application for a coffee shop step-by-step, from your first online menu to saving orders in a database. And this unique tutorial goes deeper than other beginner books. You’ll learn and practice important skills like planning applications, finding bugs, and managing user expectations.

What's inside

  • Installing Python
  • Creating text-based dialogs and menus
  • Building web applications
  • Making your web apps look professional

About the reader

For readers aged 10+. Perfect for adult beginners, too!

About the author

Pavel Anni is a Principal Customer Engineer at SambaNova Systems, and has also worked for Sun Microsystems, Oracle, and Red Hat.

Table of Contents

1 Coffee for friends: First steps
2 Lists: What’s on the menu?
3 Functions: Don’t repeat yourself!
4 User errors: Everybody makes mistakes
5 Working with files: Being a shop manager
6 Main menu: Next customer!
7 Creating functions: Get the order and print it
8 Working with JSON: Save the order
9 Complete the menu: A real program
10 Learning Flask: Your first web application
11 Web form for orders: Coffee shop on the web
12 Database: We need good storage
13 Styles: Making it pretty
14 Help from AI: Improving our code
15 Next steps: Plans for the future
LanguageEnglish
PublisherManning
Release dateJan 16, 2024
ISBN9781638354161
A Pythonic Adventure: From Python basics to a working web app
Author

Pavel Anni

Pavel Anni is a Principal Customer Engineer at SambaNovaSystems. Before joining this AI startup Pavel worked for Sun Microsystems, Oracle, and Red Hat. In his career his main role has been training people and popularizing new technologies. He has developed and delivered courses on programming languages, Unix and Linux operating systems, Kubernetes, and other important topics.

Related to A Pythonic Adventure

Related ebooks

Programming For You

View More

Related articles

Reviews for A Pythonic Adventure

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    A Pythonic Adventure - Pavel Anni

    A Pythonic Adventure

    From Python basics to a working web app

    Pavel Anni

    To comment go to liveBook

    Manning

    Shelter Island

    For more information on this and other Manning titles go to

    www.manning.com

    Copyright

    For online information and ordering of these  and other Manning books, please visit www.manning.com. The publisher offers discounts on these books when ordered in quantity.

    For more information, please contact

    Special Sales Department

    Manning Publications Co.

    20 Baldwin Road

    PO Box 761

    Shelter Island, NY 11964

    Email: orders@manning.com

    ©2024 by Manning Publications Co. All rights reserved.

    No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.

    Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.

    ♾ Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine.

    ISBN: 9781633438897

    dedication

    For my Dad

    contents

    Front matter

    preface

    acknowledgments

    about this book

    about the author

      1  Coffee for friends: First steps

    First things first: Installation

    How to talk to a computer

    What is a program?

    New things you have learned today

    Code for this chapter

    More ideas for your projects

      2  Lists: What’s on the menu?

    New things you have learned today

    Code for this chapter

      3  Functions: Don’t repeat yourself!

    New things you have learned today

    Code for this chapter

      4  User errors: Everybody makes mistakes

    New things you have learned today

    Code for this chapter

      5  Working with files: Being a shop manager

    New things you have learned today

    Code for this chapter

      6  Main menu: Next customer!

    New things you have learned today

    Code for this chapter

      7  Creating functions: Get the order and print it

    What are your choices?

    Print it!

    New things you have learned today

    Code for this chapter

      8  Working with JSON: Save the order

    New things you have learned today

    Code for this chapter

      9  Complete the menu: A real program

    New things you have learned today

    Code for this chapter

    10  Learning Flask: Your first web application

    New things you have learned today

    Code for this chapter

    11  Web form for orders: Coffee shop on the web

    New things you have learned today

    Code for this chapter

    12  Database: We need good storage

    New things you have learned today

    Code for this chapter

    13  Styles: Making it pretty

    New things you have learned today

    Code for this chapter

    14  Help from AI: Improving our code

    New things you have learned today

    15  Next steps: Plans for the future

    New things you have learned today

    Code for this chapter

    Appendix A. Ideas for your first application

    Appendix B. How to install the Mu editor and Python environment

    index

    front matter

    preface

    This book is based on a real story. My son, Erik, liked to go to Starbucks and try drinks with different flavors and toppings. One day, he decided to prepare drinks himself and treat his friends. He took his tablet to collect orders from them, but I suggested he create a simple program for that. He had tried to learn programming before, but most of the exercises were boring for him. This time, he saw a real problem he could solve with programming, and he got interested.

    That’s how this book was started. I hope you’ll find your own interesting problem that can be solved with programming—and I hope this book will help you.

    Here are a few pieces of advice:

    Don’t rush—I understand your desire to go directly to the last chapter, download the code for the final version of the program, and run it. Don’t do it. Go step by step, write the code yourself (don’t copy and paste, please!), try it, and move forward. Sometimes, you may have to return and re-read a chapter. Sometimes, you’ll need a break. Don’t worry! Take a break and repeat the chapter—just don’t drop out.

    Make mistakes—You don’t learn when everything goes perfectly well. The only way to learn is to make mistakes. Don’t be afraid of mistakes. Experiment with the code, change things, get error messages, and read them. Search for the error message on the internet, and discover thousands of other people who made the same mistake. Learn how they fixed it and then fix yours. Move ahead and don’t drop out.

    Ask questions—Ask your friends, ask your parents and grandparents, ask the internet. Explain your problem to somebody—sometimes that’s enough to figure out the solution yourself. There is no such thing as stupid questions—don’t be shy. Ask questions and don’t drop out.

    Go further—Modify the application you create with this book. Change something to make it look more like your own app. Think about other applications you can create. Look around you: what can be automated? Can you create an app that’s similar to an app or a website you know? Tell your friends about your ideas—maybe you’ll create something together. Programming is cool. Don’t drop out.

    Speak out—Please share your experience in the liveBook discussion forum. Share your thoughts and ideas with friends. Discussing problems you have solved will make your own Pythonic adventure much more interesting.

    acknowledgments

    This is my first book, and I couldn’t have written it without the invaluable support and guidance from numerous individuals.

    First and foremost, I want to express my gratitude to my parents. My dad, a firm believer in the importance of STEM education, filled our home with popular science books and encouraged me to learn programming. He astutely predicted that it would become a second literacy, and he couldn’t have been more accurate. My mom, a lifelong physics teacher, generously passed down her pedagogical genes to me.

    I must also thank my sons, Simon and Erik, for providing me with the opportunity to teach them Python. That invaluable experience allowed me to learn and grow as both an educator and a programmer.

    To my wife, Tatiana, I extend my heartfelt appreciation for her immense patience and unwavering support. She graciously endured many weekends when I focused on writing at the keyboard instead of enjoying her delightful company. Throughout the process, she listened to my thoughts and ideas, offering her invaluable advice and perspective.

    My gratitude extends to my Manning editors: Troy Dreier, Toni Arritola, and Marie-Therese Smith, who played instrumental roles in bringing this book to fruition. Troy recognized the potential in my early draft and brought it to Manning for consideration, without which this book would never have been started. Toni’s gentle yet persistent encouragement ensured the book’s timely completion. Without her, this book would never have been finished. Marie-Therese, who has worked as an educator, engineer, and data scientist, meticulously tested the code and technical details, preventing readers from stumbling on the very first coding example.

    I would like to acknowledge Nicholas H. Tollervey, the primary author of the Mu editor, and all the contributors to this fantastic open-source project. This beginner-friendly Python development environment provided everything I needed for this book’s journey, from the first steps in Python to the development of a full-stack web application.

    To all the reviewers: Afif Hayder, Al Pezewski, Alan Gil Forza, Alexis Perrier, Amogh Raghunath, Andrew R. Freed, Arsalan Khan, Arya ArunKumar, Jean-Baptiste Bang Nteme, Ben McNamara, Bernard Fuentes, Chris Kardell, Christian Sutton, Clara McAdams, Clemens Baader, David Kuhta, Dhivya Sivasubramanian, Elona Vialatte, Faiyaz Evan Hayder, Ganesh Swaminathan, George Thomas, Greg Freed, Hannah Cheung, Hasin Hayder, Jackson McNamara, Jana Dragosavljević, Janit Anjaria, Jimena de Jesús Mata Cobián, João Dinis Ferreira, Keith Kim, Kevin Cheung, Mafinar Khan, Marc-Anthony Taylor, Mary Anne Thygesen, Miguel Eduardo Gil Biraud, Nathan-Steven Taylor, Nik Piepenbreier, Ninoslav Čerkez, Or Golan, Pavel Šimon, Philippe Vialatte, Regina de Jesús Mata Cobián, Robert Kulagowski, Rupa Lahiri, Sataduru Roy, Shaurya Dara, Shivansh Batra, Shyon Roy, Sravanthi Reddy, Srisha Reddy, Srisha Thimmareddy, Sudeep Batra, Sumit Bhattacharyya, Tarun Ganesh, Tawhida Hussain, Walter Alexander Mata López, Will Pezewski, and Wolfie Baader, your suggestions helped make this a better book.

    Last, I extend my heartfelt thanks to the entire Python community. The wealth of knowledge I’ve gained from podcasts, videos, conference talks, books, and online forums over the years is immeasurable. The welcoming and supportive nature of this community is undoubtedly a significant reason why Python is so cherished by developers. Thank you all!

    about this book

    I wrote this book for teenagers who want to learn programming via practical projects. In the book, you’ll find a series of informal dialogues between two brothers working together on a Coffee Shop application. Follow their conversations and develop your own application along with them.

    Who should read this book?

    Maybe you have taken a programming class already—online or at school. You know the basics, but you haven’t tried to create a real-life project yet.

    Maybe you haven’t started with programming yet, but you know how to use a computer, and you want to learn how programming works.

    Maybe you have used some online applications, and you want to create your own.

    Maybe your older brother or sister creates computer programs and applications already, and you want to learn programming too.

    If any of the above are you—great! With this book, you’ll learn step by step with Erik and Simon and create your own application in a couple of weeks.

    If you’re a (grand)parent, and you want an easy-to-follow guide to learning programming with your (grand)children, this book is for you too! Even if you want to learn programming yourself, don’t think that this book is for kids only. Everybody is welcome to learn Python and create applications!

    How this book is organized: A roadmap

    Each chapter in this book covers what Erik and Simon (and later, Emily) created in one day. They sat together for about an hour each day, talked about their application, and wrote code. You can do the same—read a chapter a day and write the code for that chapter. If you have questions, ask them in the book’s forum or search the internet.

    There are 15 chapters in the book.

    Part 1 consists of the first 9 chapters, where Erik and Simon work on the first version of their application, which is text based. That means it works like a chat, asking customers what they want to order and waiting for their answers.

    In chapter 1, Erik gets the idea for his application. He wants to prepare coffee drinks for his friends, and he has to collect orders for them. Simon helps him create the first version of his application.

    In chapter 2, Erik learns about lists. Lists are a good way to organize your menus with different kinds of flavors and toppings.

    In chapter 3, Erik notices that he repeats his code several times. Simon suggests using functions to avoid that. The application code becomes shorter and easier to read.

    In chapter 4, Erik and Simon work on user errors. What if a customer makes a mistake when entering their order? Your application should take care of that.

    In chapter 5, Simon teaches Erik how to use files. Now the shop manager can edit text files to add or remove flavors or toppings from the menu.

    In chapter 6, the brothers create a main menu for the application. That allows them to run the application continuously and serve one customer after another.

    In chapter 7, Erik and Simon create more functions. They use functions to get the order and print it out.

    In chapter 8, Erik learns about JSON. Simon explains how to use a JSON file to store the orders.

    In chapter 9, the brothers finish the text-based version of the application. They discuss how to make a web-based version of it.

    In part 2 (chapters 10–15), Erik, Emily, and Simon work on a web version of their application. They create web-based menus, connect a database, and work on styles and colors. Finally, they test their application on smartphones and tablets.

    In chapter 10, Emily joins the brothers. Simon shows Emily and Erik how to create a very simple web application. They learn how to use web forms and menus.

    In chapter 11, Emily and Erik work on creating web forms and menus for their coffee shop.

    In chapter 12, Simon explains to Emily and Erik how to use databases to store orders. They learn how to use Structured Query Language (SQL) to do that.

    In chapter 13, the friends start making their web application pretty. They learn how to use fonts, colors, and images on web pages.

    In chapter 14, Simon shows Emily and Erik how to use artificial intelligence (AI) to improve their application code, write comments, and explain error messages.

    In chapter 15, Emily, Erik, and Simon make the application available to their smartphones and tablets and test it. It works! They discuss their next steps: how to make the application available on the cloud and how to add more features to it. They decide to continue working on the application, but to use a website to exchange their ideas.

    I suggest reading this book as a story, chapter by chapter. Please don’t skip the parts marked as YOUR TURN. You’ll have to write the code that Erik, Emily, and Simon wrote, but in your own way. Use your imagination, change things, and create your own unique application! Sometimes, you’ll want to take a break. Sometimes, you’ll want to re-read a chapter to understand it better. That’s okay. Go through the book at your own pace—just don’t drop out!

    If you’re stuck on some piece of code, try to copy it from our code repository (discussed next). If something isn’t clear, ask a question in the liveBook forum (discussed shortly).

    About the code

    The source code for this book can be found on GitHub: https://github.com/pavelanni/pythonicadventure-code. At the end of each chapter is a link to the code for that chapter. You can also get executable snippets of code from the liveBook (online) version of this book at https://livebook.manning.com/book/a-pythonic-adventure.

    This book contains many examples of source code, both in numbered listings and inline with normal text. In both cases, the source code is formatted in a fixed-width font like this to separate it from ordinary text.

    In many cases, the original source code has been reformatted; we’ve added line breaks and reworked indentation to accommodate the available page space in the book.

    Additionally, comments in the source code have often been removed from the listings when the code is described in the text. Code annotations accompany many of the listings, highlighting important concepts.

    liveBook discussion forum

    Purchase of A Pythonic Adventure includes free access to liveBook, Manning’s online reading platform. Using liveBook’s exclusive discussion features, you can attach comments to the book globally or to specific sections or paragraphs. It’s a snap to make notes for yourself, ask and answer technical questions, and receive help from the author and other users. To access the forum, go to https://livebook.manning.com/book/a-pythonic-adventure/discussion. You can also learn more about Manning's forums and the rules of conduct at https://livebook.manning.com/discussion.

    Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions lest his interest stray! The forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

    Other online resources

    The book has a companion site: https://pythonicadventure.com. On this site, we collected some ideas for other similar projects (in case you don’t like the coffee shop project), troubleshooting information, and ideas for improving the application.

    The best source for information about Python is the official site: https://www.python.org. You’ll find all the necessary documentation, blogs, articles, and tutorials there. One of the most useful sites for beginners is this collection of links to other resources: https://wiki.python.org/moin/BeginnersGuide.

    Going further

    After finishing this book, you’ll be ready to work with Python more seriously. Consider the following books as you continue your Pythonic Adventure:

    Tiny Python Projects by Ken Youens-Clark (https://www.manning.com/books/tiny-python-projects)

    Python Workout by Reuven M. Lerner (https://www.manning.com/books/python-workout)

    Practices of the Python Pro by Dane Hillard (https://www.manning.com/books/practices-of-the-python-pro)

    about the author

    Pavel Anni

    is a Principal Customer Engineer at SambaNova Systems. Before joining this AI startup, Pavel worked for Sun Microsystems, Oracle, and Red Hat. In his career, his main role has been training people and popularizing new technologies. He has developed and delivered courses on programming languages, the Unix and Linux operating systems, Kubernetes, and other topics.

    1 Coffee for friends: First steps

    In this chapter

    Erik gets an idea

    Erik and Simon discuss the future application

    Erik installs a code editor and tries to run his first program in Python

    Simon explains how to use variables

    Erik writes his first dialogue in Python

    It all started on a sunny summer day. Erik came home with an idea: he wanted to prepare coffee drinks for his friends. Who knew that he would create his own online application for that?

    I’ll make it just like at Starbucks, with many flavors and toppings, he thought. I think I have everything I need: coffee, three or four flavors to add, and some chocolate cream for toppings. Great!

    Where’s my iPad? he asked his older brother Simon.

    Where you left it. Why?

    I need it to collect orders for my coffee shop!

    He came back several minutes later with notes on his iPad, prepared four drinks for his friends, and left again.

    Wasn’t it a good idea? he asked Simon, when he came home with four empty plastic cups.

    Yes, great idea, Simon said. But . . .

    What ‘but’? Erik asked. He felt that his older brother wanted to ruin his day—as he usually did.

    "You used your iPad to take orders, but you used it just as a plain paper notepad. You could create a simple application for your coffee

    Enjoying the preview?
    Page 1 of 1