South Plantation High School logo
South Plantation High School · Procedural Programming with Python

while Loops with if Statements

while · if / elif / else · % · and / or / not · counters · input checks · 20 items · submit as a PDF

Instructions

The information on this page is not stored. If you start an assignment, you must finish it. To get a grade, you must save your results as a PDF and turn it in (steps are below).

Quick review

An if / else inside a while loop
n = 1
while n <= 4:
    if n % 2 == 0:     # 4 spaces
        print(n, "even")   # 8 spaces
    else:
        print(n, "odd")
    n += 1             # back to 4 spaces
Count only some values
count = 0
n = 1
while n <= 20:
    if n % 5 == 0:
        count += 1     # only when True
    n += 1             # every time
print(count)           # 4
Keep asking with and / or
age = int(input("Age: "))
while age < 1 or age > 120:
    print("Not a real age.")
    age = int(input("Age: "))
print("Thanks!")

Messages you may see in the terminal

How this works

  1. Enter your first name, last name initial, and class period, then click Start Assignment. Your start time is recorded.
  2. The assignment opens in a Python editor with four files (tabs). Each file holds several small programs. Each orange numbered box or drop down is one item. There are 20 items.
  3. Click ▶ Run to run every program in that file. Programs that use input() get their answers typed for you (the comment says what the user types). Run does not grade you, so compare with the expected output.
  4. When you finish all four tabs, click Submit for Score. Your end time is recorded and your score appears. Answers cannot be changed after submitting.

Turning it in: save a PDF (required for a grade)

  1. After you click Submit for Score, click the Save as PDF button at the bottom of your results.
  2. In the print window, set Destination to Save as PDF (not a printer), then click Save.
  3. Keep the file name it suggests. It already has your name and period, for example While_If_Maria_R_P3.pdf.
  4. Turn in the PDF where your teacher tells you to.

Do not refresh or close the page until your PDF is saved. Nothing is stored, so if you leave first you will have to do the assignment again. The PDF shows your name, period, times, score, every answer, and your completed code.

PartTaskItemsPoints
1Decisions inside a loop: if / elif / else and %1 to 55
2Counters, totals, and input() checks with and / or6 to 105
3Debug: = vs ==, a stuck update, or mistakes, else with a condition, and off-by-one ranges11 to 155
4Predict what each loop does16 to 205
Total (1 point per item)2020

Student Information

Reminder: nothing on this page is saved. Once you click Start Assignment, plan to finish before you leave or refresh the page.