# Currency helpers
CURRENCY_CODE = "USD" # default; will be updated by user input
def get_currency_symbol(code):
"""Return a currency symbol for a given currency code."""
code = code.strip().upper()
symbols = {
"USD": "$",
"INR": "₹",
"EUR": "€",
"GBP": "£",
"JPY": "¥",
"AUD": "A$",
"CAD": "C$"
}
return symbols.get(code, "$") # default to USD symbol
def dollars(amount):
"""Format a number using the user's chosen currency symbol."""
symbol = get_currency_symbol(CURRENCY_CODE)
sign = "-" if amount < 0 else ""
amount = abs(amount)
return f"{sign}{symbol}{amount:,.0f}"
def pct(x):
"""Format a decimal like 0.1234 as 12.34%"""
return f"{x * 100:.2f}%"
# Top 10 Domestic weekend box
def get_top10_movies():
"""Return a list of dicts with current top 10 weekend box office data."""
return [
{"rank": 1, "title": "Send Help", "weekend_gross": 20000000, "pct_lw": None, "theaters": 3475, "total_gross": 20000000, "weeks": 1},
{"rank": 2, "title": "Iron Lung", "weekend_gross": 17800000, "pct_lw": None, "theaters": 3015, "total_gross": 17800000, "weeks": 1},
{"rank": 3, "title": "Melania", "weekend_gross": 7041612, "pct_lw": None, "theaters": 1778, "total_gross": 7041612, "weeks": 1},
{"rank": 4, "title": "Zootopia 2", "weekend_gross": 5800000, "pct_lw": 0.09, "theaters": 2880, "total_gross": 408957359, "weeks": 10},
{"rank": 5, "title": "Shelter", "weekend_gross": 5505000, "pct_lw": None, "theaters": 2726, "total_gross": 5505000, "weeks": 1},
{"rank": 6, "title": "Avatar: Fire and Ash", "weekend_gross": 5500000, "pct_lw": -0.14, "theaters": 2800, "total_gross": 386126673, "weeks": 7},
{"rank": 7, "title": "Mercy", "weekend_gross": 4730000, "pct_lw": -0.56, "theaters": 3468, "total_gross": 19407819, "weeks": 2},
{"rank": 8, "title": "The Housemaid", "weekend_gross": 3500000, "pct_lw": -0.11, "theaters": 2603, "total_gross": 120686000, "weeks": 7},
{"rank": 9, "title": "Marty Supreme", "weekend_gross": 2913763, "pct_lw": -0.18, "theaters": 1703, "total_gross": 90879867, "weeks": 7},
{"rank": 10, "title": "Return to Silent Hill", "weekend_gross": 1855032, "pct_lw": -0.43, "theaters": 1608, "total_gross": 5107032, "weeks": 2},
]
def print_top10(movies):
"""Print the top 10 in a clean, numbered format."""
print("Top 10 Movies (Weekend Box Office)")
for m in movies:
print(f"{m['rank']:>2}. {m['title']:<22} {dollars(m['weekend_gross'])}")
def total_weekend_gross(movies):
"""Return the total weekend gross of all movies in the list."""
total = 0
for m in movies:
total += m["weekend_gross"]
return total
def highest_grossing(movies):
"""Return the movie dict with the highest weekend gross."""
best = movies[0]
for m in movies[1:]:
if m["weekend_gross"] > best["weekend_gross"]:
best = m
return best # <-- return AFTER the loop
def movies_over(movies, threshold):
"""Return a list of movies whose weekend gross is >= threshold."""
result = []
for m in movies:
if m["weekend_gross"] >= threshold:
result.append(m)
return result # <-- return AFTER the loop
# Numbers functions (all/odd/negative)
def print_all_numbers(numbers, label='Numbers:'):
print(label, end=' ')
for n in numbers:
print(n, end=' ')
print() # newline
def print_odd_numbers(numbers, label='Odd numbers:'):
print(label, end=' ')
for n in numbers:
if n % 2 != 0:
print(n, end=' ')
print() # newline
def print_negative_numbers(numbers, label='Negative numbers:'):
print(label, end=' ')
for n in numbers:
if n < 0:
print(n, end=' ')
print() # newline
# Main program
try:
user_code = input().strip() # user can type USD / INR / EUR etc.
if user_code != "":
CURRENCY_CODE = user_code
except EOFError:
# no input for currency keep default USD
pass
top10 = get_top10_movies()
# (Optional) show the top 10 list
print_top10(top10)
print()
print(f"Combined Top 10 weekend gross: {dollars(total_weekend_gross(top10))}")
top = highest_grossing(top10)
print(f"Highest grossing: {top['title']} with {dollars(top['weekend_gross'])}")
threshold = 5_000_000
big_openers = movies_over(top10, threshold)
print(f"Movies >= {dollars(threshold)}: ", end="")
for m in big_openers:
print(m["title"], end=" ")
print()
print()
# Create some negative numbers: (gross - threshold) will be negative if gross < threshold
diffs = []
for m in top10:
diffs.append(m["weekend_gross"] - threshold)
print("Differences from threshold (weekend_gross - 5,000,000):")
print_all_numbers(diffs, label="Numbers:")
print_odd_numbers(diffs, label="Odd numbers:")
print_negative_numbers(diffs, label="Negative numbers:")
To embed this project on your website, copy the following code and paste it into your website's HTML: