3.15 Random Number HW
Homework submission for OCS Python 3.15 Random Number
Python 3.15 Random Number
All the compiled popcorn and homework hacks for random number are below. Click Run to run the code runners.
Popcorn Hack 1: Random SFI Record Number
Code Runner Challenge
Popcorn Hack 1 Random SFI Record Number
View IPYNB Source
%%python
# CODE_RUNNER: Popcorn Hack 1 Random SFI Record Number
import random
actions = ["GET/search", "POST/create"]
record_numbers = [1, 2, 3, 4]
selected_action = random.choice(actions)
selected_record = random.choice(record_numbers)
if selected_action == "GET/search":
print(f"QA test: search for an SFI part record #{selected_record}")
else:
print(f"QA test: validate an SFI part record #{selected_record} before creating it")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Popcorn Hack 2: Random Structured SFI Car Part
Code Runner Challenge
Popcorn Hack 2 - Random SFI Part Record
View IPYNB Source
%%python
# CODE_RUNNER: Popcorn Hack 2 - Random SFI Part Record
import random
parts = [
{
"product_name": "Replacement Flywheels and Clutch Assemblies",
"category": "Auto Racing",
"spec_number": "1.1"
},
{
"product_name": "Multiple Disc Clutch Assemblies",
"category": "Drag Racing",
"spec_number": "1.2"
},
{
"product_name": "Racing Flywheel Record",
"category": "Auto Racing",
"spec_number": "2.1"
}
]
print("---One Complete Structured Record with random.choice()---")
selected_record = random.choice(parts)
print("Product Name:", selected_record["product_name"])
print("Category: ", selected_record["category"])
print("Spec Number: ", selected_record["spec_number"])
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Popcorn Hack 3: Random SFI API Test
Code Runner Challenge
Popcorn Hack 3 - Random SFI API Test
View IPYNB Source
%%python
# CODE_RUNNER: Popcorn Hack 3 - Random SFI API Test
import random
parts = [
{"product_name": "Replacement Flywheels", "spec_number": "1.1"},
{"product_name": "Multiple Disc Clutch Assemblies", "spec_number": "1.2"},
{"product_name": "Racing Flywheel Record", "spec_number": "2.1"}
]
actions = [
"GET/search",
"POST/create",
"PUT/update"
]
selected_part = random.choice(parts)
selected_action = random.choice(actions)
if selected_action == "GET/search":
print("Searching backend for record for part:", selected_part)
elif selected_action == "POST/create":
print("Creating record for part:", selected_part)
elif selected_action == "PUT/update":
print("Updating record for part:", selected_part)
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
MCQ Check
MCQ 3.15: 4/4 | answers: C,B,B,B
Homework Hack (independent): SFI Backend QA Simulator
Code Runner Challenge
Homework Hack
View IPYNB Source
%%python
# CODE_RUNNER: Homework Hack
# Homework Hack - SFI Backend QA Simulator
import random
parts = [
{
"product_name": "Replacement Flywheels",
"category": "Auto Racing",
"spec_number": "1.1"
},
{
"product_name": "Multiple Disc Clutch Assemblies",
"category": "Drag Racing",
"spec_number": "1.2"
},
{
"product_name": "Racing Flywheel Record",
"category": "Auto Racing",
"spec_number": "2.1"
}
]
actions = [
"GET/search",
"POST/create",
"PUT/update",
"DELETE/remove"
]
existing_spec_numbers = ["1.1", "2.1"]
test_count = 4
# Build and test your QA simulator below.
def run_qa_test(test_number):
selected_part = random.choice(parts)
selected_action = random.choice(actions)
spec = selected_part["spec_number"]
name = selected_part["product_name"]
print(f"--- Test {test_number} ---")
print(f"Selected Part: {name} (Spec {spec}, {selected_part['category']})")
print(f"Selected Action: {selected_action}")
if selected_action == "GET/search":
print(f"Result: Searching backend for '{name}' (Spec {spec})...")
elif selected_action == "POST/create":
duplicate_spec = spec in existing_spec_numbers
if duplicate_spec:
print(f"Result: REJECTED — Spec {spec} already exists in backend.")
else:
print(f"Result: ACCEPTED — Creating new record for '{name}' (Spec {spec}).")
elif selected_action == "PUT/update":
print(f"Result: Updating existing record for '{name}' (Spec {spec})...")
elif selected_action == "DELETE/remove":
print(f"Result: Removing record for '{name}' (Spec {spec}) from backend...")
print()
for i in range(1, test_count + 1):
run_qa_test(i)
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...