Python中文
首页
教程
问答
标签
搜索
登录
注册
在Python中解包的值太多
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正试图制作一个战舰游戏,但我被困在船的一代。 当我试着运行这个程序时:</p> <h3>初始化</h3> <pre><code>print "Welcome to Battleships!!!" board = [] import os from random import randint for x in range(10): board.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(["O"] * 10) def print_board(board): for row in board: print " | ".join(row) ships = {"battleship" : [5], "cruiser1" : [4], "cruiser2" : [4], "frigate1" : [3], "frigate2" : [3], "frigate3" : [3], "frigate4" : [3], "minesweeper1" : [2], "minesweeper2" : [2], "minesweeper3" : [2], "minesweeper4" : [2]} numbers1 = [] numbers2 = [] numbers = [] </code></pre> <h3>一些设置功能</h3> ^{pr2}$ <h2>主程序</h2> <pre><code>setup_nums1() setup_nums2() setup_ships() print numbers1 print numbers2 print ships </code></pre> <p>我得到这个错误:</p> <pre><code>Welcome to Battleships!!! Traceback (most recent call last): File "/home/matthew/Documents/battleship2.py", line 77, in <module> setup_ships() File "/home/matthew/Documents/battleship2.py", line 41, in setup_ships for ship, info in ships: ValueError: too many values to unpack </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>要解包的值太多意味着调用的函数返回多个值,而您只处理其中的一些值。在</p> <p>问题出在</p> <pre><code>for ship, info in ships: </code></pre> <p>这一定是</p> ^{pr2}$ <p><strong>或</strong></p> <pre><code>for ship, info in ships.iteritems(): </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在Excel中读取公式并将其转换为Python中的计算?
7 回答
如何在excel中读取嵌入的excel,并将嵌入文件中的信息存储在主excel文件中?
3 回答
如何在Excel中返回未知列长度的非空顶行列值?
7 回答
如何在excel中选择数据列?
8 回答
如何在Excel中通过脚本自动为一列中的所有单元格创建公共别名
8 回答
如何在excel中高效格式化范围AttributeError:“tuple”对象没有属性“fill”
8 回答
如何在excel单元格中编写python函数
5 回答
如何在excel单元格中自动执行此python代码?
9 回答
如何在excel工作表中创建具有相应值的新列
5 回答
如何在Excel工作表中复制条件为单元格颜色的python数据框?
7 回答
如何在Excel工作表中循环
6 回答
如何在excel工作表中打印嵌套词典?
3 回答
如何在excel工作表中绘制所有类的继承树?
2 回答
如何在Excel工作表中自动调整列宽?
2 回答
如何在excel工作表中追加并进一步处理
6 回答
如何在excel工作表之间进行更改?
5 回答
如何在excel或csv上获取selenium数据?
4 回答
如何在Excel或Python中将正确的值赋给正确的列
9 回答
如何在excel或python中提取单词周围的文本?
2 回答
如何在excel或python中转换来自Jira的3w 1d 4h的fromat数据?
9 回答