Skip to content

Instantly share code, notes, and snippets.

@zinthose
Created April 12, 2024 06:54
Show Gist options
  • Save zinthose/030f54c7f1bddd74e6387ebf925d3685 to your computer and use it in GitHub Desktop.
Save zinthose/030f54c7f1bddd74e6387ebf925d3685 to your computer and use it in GitHub Desktop.
I created this template for use on the WGU inscribe forums when posting python code as the in post code sample editor doesn't allow for the use of the input() function. To address this, I overrode the build in function as shown in this example.
#┊ ⚠ Overwrite input() function to take inputs from a list ⚠
#╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
_i, _, _P, input = [], lambda v: _i.append(v.splitlines()[1::]), lambda p: print(p, end="") if p else None, lambda p=None: _i[0].pop(0) if _P(p) is None else _i[0].pop(0)
#┌──────────────────────────
#│ ✔ INPUT LINES GO HERE ✔
#└──────────────────────────
_('''
3
SOFI
AMZN
LVLU
''')
#┌────────────────────────────
#│ ✔ LAB CODE STARTS HERE ✔
#└┬─────────────────────────────────────────
# │ 34.10 PRACTICE: Dictionary key search
# ╰─────────────────────────────────────────
stocks = {'TSLA': 912.86, 'BBBY': 24.84, 'AAPL': 174.26, 'SOFI': 6.92, 'KIRK': 8.72, 'AURA': 22.12, 'AMZN': 141.28, 'EMBK': 12.29, 'LVLU': 2.33}
# Get data from user inputs
_count, stock_list = (count := int(input())), [input() for each in range(count)]
# Calculate total price
total = sum(stocks[stock] for stock in stock_list)
print(f'Total price: ${total:.2f}')
#┌───────────────────────────
#│ ✘ LAB CODE STOPS HERE ✘
#└───────────────────────────
@zinthose
Copy link
Author

Sample output is:

Total price: $150.53

@zinthose
Copy link
Author

I know that the first line is ugly. Try to think of it as minified code that the students would never need to touch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment