本文目录导读:

我理解您想要一个能显示两支球队被射门次数对比的实用脚本,这里为您提供三种常见场景的解决方案:
足球比赛数据对比脚本(Python + 命令行)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
足球比赛被射门次数对比工具
用法: python shots_against.py 主场队名 客场队名 主场被射门数 客场被射门数
"""
import sys
import json
from datetime import datetime
class ShotComparison:
def __init__(self, home_team, away_team, home_against, away_against):
self.home_team = home_team
self.away_team = away_team
self.home_against = home_against
self.away_against = away_against
def compare(self):
"""进行对比分析"""
diff = self.home_against - self.away_against
total = self.home_against + self.away_against
print("\n" + "="*50)
print("⚽ 被射门次数对比报告")
print("="*50)
print(f"比赛时间: {datetime.now().strftime('%Y-%m-%d %H:%M')}")
print(f"\n🏠 主队: {self.home_team} | 被射门: {self.home_against} 次")
print(f"🚗 客队: {self.away_team} | 被射门: {self.away_against} 次")
print("-"*50)
# 计算百分比
home_pct = (self.home_against / total * 100) if total > 0 else 0
away_pct = (self.away_against / total * 100) if total > 0 else 0
print(f"主队占比: {home_pct:.1f}% | 客队占比: {away_pct:.1f}%")
print(f"差值: {abs(diff)} 次 ({'主队更多' if diff > 0 else '客队更多' if diff < 0 else '持平'})")
# 生成简单的ASCII图表
max_val = max(self.home_against, self.away_against, 1)
home_bar = '█' * int(20 * self.home_against / max_val)
away_bar = '█' * int(20 * self.away_against / max_val)
print("\n可视化对比:")
print(f"{self.home_team}: {home_bar} ({self.home_against})")
print(f"{self.away_team}: {away_bar} ({self.away_against})")
# 分析结论
print("\n📊 分析结论:")
if diff > 5:
print(f"⚠️ {self.home_team}防守压力明显增大")
elif diff < -5:
print(f"⚠️ {self.away_team}防守压力明显增大")
elif abs(diff) <= 2:
print("✅ 双方被射门次数接近,比赛均衡")
else:
print("📈 双方防守表现存在一定差异")
return {
'home_team': self.home_team,
'away_team': self.away_team,
'home_against': self.home_against,
'away_against': self.away_against,
'difference': diff,
'timestamp': datetime.now().isoformat()
}
def main():
if len(sys.argv) != 5:
print(__doc__)
sys.exit(1)
home_team = sys.argv[1]
away_team = sys.argv[2]
try:
home_against = int(sys.argv[3])
away_against = int(sys.argv[4])
if home_against < 0 or away_against < 0:
raise ValueError("被射门次数不能为负数")
except ValueError as e:
print(f"错误: 请输入有效数字 - {e}")
sys.exit(1)
# 创建对比对象并执行
comparison = ShotComparison(home_team, away_team, home_against, away_against)
result = comparison.compare()
# 可选:保存为JSON文件
with open('match_stats.json', 'w', encoding='utf-8') as f:
json.dump(result, f, ensure_ascii=False, indent=2)
print("\n📁 数据已保存至 match_stats.json")
if __name__ == "__main__":
main()
Web界面版本(HTML + JavaScript)
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">足球被射门对比工具</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
padding: 20px;
}
.container {
background: white;
border-radius: 20px;
padding: 40px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
max-width: 600px;
width: 100%;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
.input-group {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 20px;
}
.team-input {
padding: 12px;
border: 2px solid #ddd;
border-radius: 8px;
font-size: 16px;
transition: border-color 0.3s;
}
.team-input:focus {
outline: none;
border-color: #667eea;
}
button {
width: 100%;
padding: 15px;
background: #667eea;
color: white;
border: none;
border-radius: 8px;
font-size: 18px;
font-weight: bold;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}
.result {
margin-top: 30px;
display: none;
background: #f8f9fa;
border-radius: 12px;
padding: 25px;
}
.comparison-bar {
display: flex;
align-items: center;
margin: 15px 0;
}
.bar-label {
width: 100px;
font-weight: bold;
text-align: right;
margin-right: 15px;
white-space: nowrap;
}
.bar-container {
flex-grow: 1;
background: #eee;
border-radius: 6px;
height: 30px;
overflow: hidden;
}
.bar-fill {
height: 100%;
background: linear-gradient(90deg, #667eea, #764ba2);
border-radius: 6px;
transition: width 1s ease;
position: relative;
}
.bar-fill span {
position: absolute;
right: -50px;
top: 50%;
transform: translateY(-50%);
font-weight: bold;
}
.analysis {
margin-top: 20px;
padding: 15px;
background: #e3f2fd;
border-radius: 8px;
border-left: 4px solid #2196f3;
}
.error {
color: #f44336;
margin-top: 10px;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<h1>⚽ 被射门次数对比</h1>
<div class="input-group">
<div>
<input type="text" class="team-input" id="homeTeam" placeholder="主队名称">
<input type="number" class="team-input" id="homeShots" placeholder="主队被射门次数" min="0" style="margin-top:10px">
</div>
<div>
<input type="text" class="team-input" id="awayTeam" placeholder="客队名称">
<input type="number" class="team-input" id="awayShots" placeholder="客队被射门次数" min="0" style="margin-top:10px">
</div>
</div>
<button onclick="compare()">开始对比</button>
<div class="error" id="error"></div>
<div class="result" id="result">
<div id="resultContent"></div>
</div>
</div>
<script>
function compare() {
const homeTeam = document.getElementById('homeTeam').value;
const awayTeam = document.getElementById('awayTeam').value;
const homeShots = document.getElementById('homeShots').value;
const awayShots = document.getElementById('awayShots').value;
// 清除错误信息
document.getElementById('error').textContent = '';
// 输入验证
if (!homeTeam || !awayTeam) {
document.getElementById('error').textContent = '请输入球队名称';
return;
}
const home = parseInt(homeShots);
const away = parseInt(awayShots);
if (isNaN(home) || isNaN(away) || home < 0 || away < 0) {
document.getElementById('error').textContent = '请输入有效的被射门次数(非负整数)';
return;
}
// 生成结果
const total = home + away;
const homePct = total > 0 ? (home / total * 100).toFixed(1) : 0;
const awayPct = total > 0 ? (away / total * 100).toFixed(1) : 0;
const resultDiv = document.getElementById('result');
const content = document.getElementById('resultContent');
content.innerHTML = `
<h3 style="margin-bottom:20px; text-align:center">比赛分析报告</h3>
<div class="comparison-bar">
<div class="bar-label">${homeTeam}</div>
<div class="bar-container">
<div class="bar-fill" style="width:${homePct}%;">
<span>${home}次</span>
</div>
</div>
</div>
<div class="comparison-bar">
<div class="bar-label">${awayTeam}</div>
<div class="bar-container">
<div class="bar-fill" style="width:${awayPct}%;">
<span>${away}次</span>
</div>
</div>
</div>
<div class="analysis">
<strong>📊 数据分析:</strong><br>
<p>总被射门次数:${total}次</p>
<p>${homeTeam}占比:${homePct}%</p>
<p>${awayTeam}占比:${awayPct}%</p>
${home > away ? `<p>⚠️ ${homeTeam}防守压力更大</p>` :
away > home ? `<p>⚠️ ${awayTeam}防守压力更大</p>` :
'<p>✅ 双方防守表现均衡</p>'}
</div>
`;
resultDiv.style.display = 'block';
}
// 添加回车键支持
document.addEventListener('keypress', function(event) {
if (event.key === 'Enter') {
compare();
}
});
</script>
</body>
</html>
使用说明
方案一(命令行版本):
# 基本用法 python shots_against.py 曼联 利物浦 14 8 # 输出示例 ⚽ 被射门次数对比报告 ================================================== 主队: 曼联 | 被射门: 14 次 客队: 利物浦 | 被射门: 8 次
方案二(Web版本):
直接保存为 .html 文件并用浏览器打开即可。
扩展建议
- 数据存储:可集成数据库存储历史数据
- 更多指标:增加控球率、射正数等对比
- 可视化升级:使用Chart.js或D3.js绘制更精美的图表
- 实时更新:连接API获取实时比赛数据
您需要哪种场景的具体实现?我可以提供进一步定制。
版权声明:NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播