Page 103 - Programming With Python 3
P. 103
An Introduction to STEM Programming with Python — 2019-09-03a Page 90
Chapter 7 — In, If, Random, and While
Free
eBook
Edition
Please support this work at
Illustration 16: Flowchart of If Elif
http://syw2l.org
Three ways to do the same thing
Free
The three programs, below, actually do the exact same thing. They each illustrate a different way to use
if statements. This program will generate random grades for teacher when they don't want to grade
papers. They have decided that 10% of students will get an A, 15% will get a "B", 50% will get a "C",
15% a "D", and the remaining 10% will get an "F" and that the grade will be assigned randomly.
eBook
Edition
Illustration 17: Lazy Professor Problem
Way One: Using complex if statements so that only one grade will be displayed. The conditions in
the if statements need to cover the full range of values returned by random.random() but have no
Copyright 2019 — James M. Reneau Ph.D. — http://www.syw2l.org — This work is licensed
under a Creative Commons Attribution-ShareAlike 4.0 International License.

