- scratchpad.py
- Unit Test
Test Cases
x/x
Pass | Test | Message | |
---|---|---|---|
- | Test results will show here. | - |
Errors:
Problem Statement
In 1776, the United States declared its independence from Great Britain. This momentous event was marked by the signing of the Declaration of Independence. To celebrate this historical event, you are to write a Python function that processes a list of key figures involved in the Revolutionary War and returns some interesting statistics about them.
Instructions
You will write a function revolutionary_war_stats()
that takes a list of dictionaries as input (people
). Each dictionary represents a key figure from American history, and contains the following keys:
- “name”: a string representing the person’s name
- “side”: a string representing the side they fought for, either “American” or “British”
- “role”: a string representing their role, such as “General”, “Soldier”, “Spy”, etc.
Your function should return a tuple containing:
1. The total number of people in the list.
2. The number of people who fought for the American side.
3. The number of Generals on the American side.
4. The number of people who were Spies, regardless of the side.
Example
Input: [{"name": "George Washington", "side": "American", "role": "General"}, {"name": "Benedict Arnold", "side": "American", "role": "General"}, {"name": "John Andre", "side": "British", "role": "Spy"}, {"name": "Nathan Hale", "side": "American", "role": "Spy"}, {"name": "William Howe", "side": "British", "role": "General"}]
Expected Result: (5, 3, 2, 2)
Upload an image
Upload from your computer
Or paste a link here
Slides and Notes
No slides available for this video
About
Python 3 Practice
3.11.9 (default, Apr 6 2024, 17:59:24)
[GCC 6.4.0]