livepython.net

144. Python Program to Rename Functions and Constants in PEP 8 Style

MediumNaming

Overview

Every naming style is mixed up in this program: camelCase, PascalCase, ALL CAPS and single letters. Give each name the right PEP 8 style.

Problem Statement

The starter code reads a line of marks, then prints their total and how many of them are 40 or more. For example, for 35 80 52:

Total: 167
Passed: 2

Rewrite it with PEP 8 names:

  • the pass mark is a constant, so write it in UPPER_CASE,
  • function names in snake_case, starting with a verb,
  • variables in snake_case with clear names: no single letters, and never l,
  • one space around =, += and >=, one after each comma, and two blank lines before and after each function.

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

The tests check only the output, and the starter code already prints the right thing. So they can't see your names: check every name against the list yourself.

Input

One line with whole numbers separated by spaces. Example:

35 80 52

Output

The output for that example:

Total: 167
Passed: 2

The tests try 4 different inputs.

Learn this firstChapter 16 · Python Naming Conventions: snake_case, UPPER_CASE and More
solution.py
passMark=40
def GetTotal(L):
    T=0
    for X in L:
        T+=X
    return T
def COUNTPASSES(L):
    c=0
    for X in L:
        if X>=passMark:
            c+=1
    return c
l=[]
for p in input().split():
    l.append(int(p))
print("Total:",GetTotal(l))
print("Passed:",COUNTPASSES(l))

EXPECTED OUTPUT

1Total: 167
2Passed: 2

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.