Skip to main content
Chemistry LibreTexts

2.1: FlowCharts and Python

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\) tag: s20iostpy01ualr

    Download Assignment S2020Py01

    Download Assignment LASTname_Fall2020_Py01

    Learning Objectives

    Students will be able to:


    • Explain how to display data in Python using Thonny IDE
    • Explain how to create a comment in Python
    • Determine the difference between a string literal and a number


    • Create print statements in Python3
    • Create Python code that displays results to calculated addition and multiplication facts

    Task 1: Update Anaconda

    Your install of Anaconda is a fresh install, but there may have been updates to python libraries since the installation package was released. To update your anaconda package complete the following:

    1. In the start menu, type Anaconda to bring up the anaconda prompt. Click on the prompt to start anaconda.
    installing anacondaFigure \(\PageIndex{1}\): Windows 7 & 10 screen shots

    This will bring up your anaconda prompt in a new command window.

    2.  Type conda update anaconda at the prompt and press enter (note: you may be prompted to type conda update -n base conda)

    conda update anaconda
    Figure \(\PageIndex{2}\): Screenshot of command line for updating anaconda

    3.  You will see that conda will determine what packages need to be updated. You should see a spinning cursor in the following window next to solving environment

    Figure \(\PageIndex{3}\):  Screenshot of command as anaconda  determines which packages need updating (this is an advantage to installing Anaconda as you can update all your packages at the same time).

    4. There may or may not be packages that need to be updated. You can see in the screen below that there are many packages that need to be updated. Click y and enter to proceed:

    fig 3b
    Figure \(\PageIndex{4}\):  Screenshot of command line showing packages that need updating

    5. You will see it updating as shown below. Specifically, you can see that the last line indicates that python needed to be updated. It will not download, extract and install updates.  As it installs, the percent by each line will go from 0 to 100%

    updating conda
    Figure \(\PageIndex{5}\): Screenshot of command line showing updates in progress

    6. When it is complete, it will let you know:

    Figure \(\PageIndex{6}\): Screenshot of command line showing that all modules have been installed.

     Task 2- Watch video on Thonny:



    Additional Thonny tutorials:

    Step Through Python Scripts With Thonny (video)


    Model 1: Printing in Python

    Output, one of the of the four main operations of a computer, is performed using a print statement in Python.


    Python Program


    print("The atomic number")
    print("for carbon is")

    The atomic number
    for carbon is



    In your Thonny python shell, type the first line of python code above and press enter.

    Critical Thinking Questions:

    1. What does the first line of Python code in the Python program do?
    2. Circle the Python code’s equivalent representation in the flowchart.
    3. Using the Thonny python shell, enter and execute the following statements. What does the code produce when executed?


    print("Hello, my name is Monty!")


    1. Was there a problem with any of the sample code in question 3?  If so, what caused the problem? 
    2. What caused the different formatting of output for samples “a” and “c” in question 3/
    3. Using the Thonny python shell, enter and execute the following statements. What do the following Python statements output?


    Exercise \(\PageIndex{1}\)

    Predict the results of each print statement and then using either the Thonny python shell on your computer or the Binder access to the LibreText Jupyter Hub validate your answers (you can cut and paste each question into the IDE/binder, the first one is already loaded)

    1. print (2+5)
    2. print (2*5)
    3. print ('2+5')
    4. print ("Age:",7)
    5. print ('Age:',2+5, "years")
    Answer a

    Answer b


    Answer c


    Answer d

    Age: 7

    Answer e

    Age: 7 years


    a.   print(2+5)
    b.   print(2*5)
    c.   print("2+5")
    d.   print("Age:",20)
    e.   print("Age:",2*10,"years")
    1. Examine the output for each statement in question 6.

    a.  What is the difference in the output for the statements in “a” and “c” of question 6? 

    b.  What caused the difference?

    c.  Which of the statements contains a string literal?

    d.  What does the comma (,) do in the print statement in part “d” of question 6? How does it affect  the  spacing of the output?

    e.  Can you include both string literals and calculations in the same print statement? Explain.

    Model 2: Documentation in Python

    Documenting a program is essential for you as well as for others who may need to enhance or update your program at some future time. Any documentation or commenting in Python should begin with a “#”.  The interpreter will ignore anything that comes after the “#” on a given line. See the example below.

    Python Program


    # Programmer: Monty Python
    # Date: 3/15/2018
    # Description: This program demonstrates the use of print
    # statements
    print("The mass of 0.5 moles of water is")

    The mass of 0.5 moles of water is
    9.01 grams

    Task 3: Run the program in Run current script mode.

    In your Thonny IDE, choose File/New file.
    In your Thonny IDE, choose File/Save and title the save file as Program1, and be sure to save as type “Python files”.

    Copy the python program above into the editor window of your Thonny IDE.
    Run the program by clicking the green run button , or hitting F5 of your function keys.
    The output of the file will be shown in the shell window.


    Task 4: Run the program again in debug mode.

    To do so either go to menu Run/Debug current script or by clicking ctrl+F5


    Critical Thinking Questions

    1. Examine the previous code and its output. What do the first four lines of the program do?  (What did the python interpreter do with those four lines in debug mode?)
    2. What would happen if you placed a “#” in front of the code: print(0.5*18.02,"grams") in the previous program?

    (after you predict what happens, put a # in front of the print statement, and rerun the program.)

    Model 3: Computer system basic functions

    There are four basic functions of a computer system:


    The act of transferring information into the computer system. This can be achieved by using an input device (such as a keyboard or mouse), or through a previously stored program file.



    The display of information from within the system to a user.



    The manipulation and control of data.



    The ability to save data in temporary and long-term repositories. Temporary data is stored in RAM, and long-term storage takes place on hard drives.

    10.  using what you have done today as a guide, provide examples of how you employed each of the four basic functions of a computer in this activity

    Application Questions: Use the Thonny Python Editor and Shell windows to check your work

    1.  Create a Python program containing four statements to implement the flowchart in below. Write the statements next to the flowchart and test your work.


    2. Create one line of Python code that produces the output expected from the flowchart in application question 1 except that it is outputted on only 1 line.
    (e.g. your output will be The formula weight of cyclohexane is 84.16 g/mol.

    3.  Create a Python program containing two statements that prints the following output.  Have the program calculate the answers to the two arithmetic problems.

    fig 7

    HomeWork Assignment

    At the top of this page you can download a Word document that you can do your assignment in and then upload to the Google Drive folder.


    1)      After reading the, create a flowchart using that would describe heating a sample to constant mass. The following video is a nice overview of how to use it (5 points)

    [Insert Image Here]


    2)      Create a Python program that prints out the following information and upload it as a python file with the following file name  (the ".py" is the python file extension) (10 pts)


    Line 1 prints out the name of an element and its atomic mass

    Line 2 prints out the name of another element and its atomic mass

    Line 3 prints out the value of the addition of the atomic masses of the two elements

    Line 4 prints out the value of the product of the atomic masses of the two elements


    Sample Printout for Hydrogen and Chlorine would look like:


    Hydrogen: 1.008

    Chlorine: 35.453

    Sum: 36.461

    Product: 35.734



    Your program must contain documentation lines that include your name, the date, a line that states “Py01 Homework question 2” and a description line or two that indicates what the program is supposed to do.  Take a screen shot of the program and the output and attach below:

    [Insert Screenshot Here] (note, adjust all images so that they do not span a page break).


    Python uses multiple data types.  Using, find two different sites that describe data types in Python and write below a description of the difference between integers, floating point numbers and string literals.  Be sure to tag the annotations with the chapter's tag: S20IOSTpy01ualr (case sensitive)


    Copyright Statement

    This work  is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, this material is a modification by Ehren Bucholtz and Robert Belford of CS-POGIL content, with the original material developed by Lisa Olivieri, which is available here.


    This page titled 2.1: FlowCharts and Python is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?