MEDALS = 3
COUNTRIES = 8
# Create a list of country names.
countries = [ "Canada", "Italy", "Germany", "Japan",
"Kazakhstan", "China",
"South Korea", "United States" ]
# Create a table of medal counts.
counts = [
[ 0, 3, 0 ],
[ 0, 0, 1 ],
[ 0, 0, 1 ],
[ 1, 0, 0 ],
[ 0, 0, 1 ],
[ 3, 1, 1 ],
[ 0, 1, 0 ],
[ 1, 0, 1 ]
]
print(' Country Gold Silver Bronze Total')
for v in countries:
country = v
print("{:>13}".format(country))
for row in range(COUNTRIES):
for col in range(MEDALS):
print(counts[row][col],end = ' ')
print('')
应该在不使用任何导入模块的情况下解决这个问题。我该如何做到这一点,请向我解释一下?非常感谢你。
尝试运行我的代码,但它不起作用
您的代码现在显示:打印所有国家/地区
for v in countries:
,然后打印所有奖牌for row in range(COUNTRIES)
,要打印表格,您需要将第二个循环嵌套在第一个循环中。